0
我已經使用自定義列表視圖來顯示圖像和我的列表視圖中的文本信息,使用散列表和兩個xml佈局,其中一個包含listview,另一個包含自定義行。下面的代碼工作得很好。我應該如何敬酒用戶點擊行的位置?我如何顯示在自定義列表視圖中點擊的項目的位置
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);
}
}
它不返回位置 –
它是否返回列表項索引如0,1,2當你點擊列表項 –
它不返回任何東西,它甚至沒有突出顯示我點擊的行 –