안녕하세요.
Array로 구성된 listview에서 device 네임 값만 추출해서 특정 네임 값이 있는 경우에 버튼을 enabled 하려고 하는데 감이 도무지 잡히지 않습니다.. 고수분들 조언 부탁드립니다.
public class Device extends Activity implements OnItemClickListener {
private ArrayList<BluetoothDevice> devices;
private List<Map<String, String>> listItems = new ArrayList<Map<String, String>>();
private SimpleAdapter adapter;
private Map<String, String> map = null;
private ListView listView;
private String DEVICE_NAME = "name";
private String DEVICE_ADDRESS = "address";
public static final int RESULT_CODE = 31;
public final static String EXTRA_DEVICE_ADDRESS = "EXTRA_DEVICE_ADDRESS";
public final static String EXTRA_DEVICE_NAME = "EXTRA_DEVICE_NAME";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.device_list);
getActionBar().setDisplayHomeAsUpEnabled(true);
setTitle("Device");
listView = (ListView) findViewById(R.id.listView);
devices = (ArrayList<BluetoothDevice>) BLESelect.mDevice;
for (BluetoothDevice device : devices) {
map = new HashMap<String, String>();
map.put(DEVICE_NAME, device.getName());
map.put(DEVICE_ADDRESS, device.getAddress());
listItems.add(map);
}
Button btn = (Button)findViewById(R.id.button1);
if ( R.layout.list_item == "PT2480"){
btn.setEnabled(true);
}
adapter = new SimpleAdapter(getApplicationContext(), listItems,
R.layout.list_item, new String[] { "name", "address" },
new int[] { R.id.deviceName, R.id.deviceAddr });
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
// EditText text = (EditText) findViewByID(R.id.editText1)
// editText1.setText(R.id.deviceName);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view,
int position, long id) {
HashMap<String, String> hashMap = (HashMap<String, String>) listItems
.get(position);
String addr = hashMap.get(DEVICE_ADDRESS);
String name = hashMap.get(DEVICE_NAME);
Button btn = (Button)findViewById(R.id.button1);
Intent intent = new Intent();
intent.putExtra(EXTRA_DEVICE_ADDRESS, addr);
intent.putExtra(EXTRA_DEVICE_NAME, name);
setResult(RESULT_CODE, intent);
finish();
}
}