how can i show position of item clicked in customized listview
I have use a custom listview to display images and also text information
in my listview using hashmap and two xml layouts, of which on contains the
listview and the other contains the custom rows. And the code below works
just fine. How should I toast the position of the row a user click ??
public class MainTopic extends Activity{
ListView mtopiclv;
LinearLayout header;
List<HashMap<String, String>> rowList;
String[] topicHeader ={
"What is farming ?",
"Raising animals ?",
"How to graz ?",
"sdsdsdsd sdsd",
"Control",
"Find product centers",
"Research and statistics",
"How to succeed in sdfsdfds ?"
};
String[] info = {
"Introduction, benefits",
"Seeds, planting and care",
"Requirements, , resources",
"Investing in farming",
"Practices and tools",
"machinery",
"books",
"Business tips"
};
int[] images = {
R.drawable.sample_1,
R.drawable.sample_2,
R.drawable.sample_3,
R.drawable.sample_4,
R.drawable.sample_5,
R.drawable.sample_6,
R.drawable.sample_7,
R.drawable.sample_8
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mtopic);
setUp();
hashmap();
}
private void hashmap() {
// TODO Auto-generated method stub
rowList = new ArrayList<HashMap<String, String>>();
//looping through all items
for(int i = 0; i<8; i++){
HashMap<String, String> infoList = new HashMap<String, String>();
infoList.put("topicHeader", topicHeader[i]);
infoList.put("info", info[i]);
infoList.put("imgs", Integer.toString(images[i]));
rowList.add(infoList);
//from
String[] from = {"topicHeader", "info", "imgs"};
int[] to = {R.id.clvHeader, R.id.clvsum, R.id.imgbtn};
//adapter
SimpleAdapter clvAdapter = new SimpleAdapter
(getApplicationContext(), rowList, R.layout.mtopic_custome_lv,
from, to);
mtopiclv.setAdapter(clvAdapter);
}
}
private void setUp() {
// TODO Auto-generated method stub
mtopiclv = (ListView) findViewById(R.id.mtopiclv);
header = (LinearLayout) findViewById(R.id.header);
}
}
No comments:
Post a Comment