我是 android 新手,我在我的 android 中使用 edittext 搜索工作正常,搜索代码如下:
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
// TODO Auto-generated method stub
// When user changed the Text
arrayAdapter.getFilter().filter(s);
arrayAdapter.notifyDataSetChanged();
}
..........
}}
我正在使用 simpleadapter 在具有两个列 col1,col2 的列表视图中显示数据:
arrayAdapter = new SimpleAdapter(LabelUser.this, mylistData,
R.layout.two_col_row, columnTags, columnIds);
list.setAdapter(arrayAdapter);
点击列表:
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v,
int position, long id) {
// TODO Auto-generated method stub
String selectedFromList = (list.getItemAtPosition(position).toString());
System.out.println(selectedFromList);
startActivity(new Intent("com.example.mysampleapp.DASHBOARDTAB"));
}
});
并给出输出:
{col1=A K JOHN, col2=21.45}
我的问题是如何从上面获取一个字符串,即 col1
例如 var = "AK JOHN"
列表视图创建:
final ListView list = (ListView) findViewById(R.id.listView1);
ArrayList<HashMap<String, String>> mylistData = new ArrayList<HashMap<String, String>>();
String[] columnTags = new String[] { "col1", "col2" };
int[] columnIds = new int[] { R.id.column1, R.id.column2 };
for (int i = 0; i < labelIdArray.length; i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("col1", labelArray[i]);
map.put("col2", labelRateArray[i]);
mylistData.add(map);
list.setAdapter(arrayAdapter);
}