我是android的新手我使用edittext搜索在我的android中搜索工作正常,搜索代码如下:
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在listview中显示有两个colomn 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 =“A K JOHN”
listview创建:
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);
}
答案 0 :(得分:0)
如果你想获取第一列的值,我认为以下代码可以正常工作,
String selectedFromList = columnTags[position];
试着试着告诉它是否有用。