我創建了一個ExpandableList View
以及一些組項目和相應的子項目。如何在ExpandableListView的子視圖上處理兩個ImageButtons
我可以到達子視圖,並在groupPosition
和childPosition
的幫助下訪問子視圖屬性。
現在,我必須在這個每個子視圖上放置兩個ImageButton
,並在點擊每個子視圖時觸發不同的Intents。
我試圖代碼來設置onClickListeners
每個圖像按鈕,並得到相應的結果,但我遇到困難的返回值,其中只有一個View
的getChildView
回報。
如何獲得每個ImageButton
的點擊響應?
我的代碼如下:
public View getChildView (final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
final View providbtn = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
final View lecvidbtn = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
final ImageButton providbtn1 = (ImageButton)providbtn.findViewById(R.id.provid);
final ImageButton lecvidbtn1 = (ImageButton)lecvidbtn.findViewById(R.id.lecvid);
//final View childItemClicked = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
//final ImageButton ib = (ImageButton)childItemClicked.findViewById(R.id.)
//ImageButton provid = (ImageButton)findViewById(R.id.provid);
providbtn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplication(), "Topic Proc video is: "+topic[groupPosition]+" and Chapter is "+chapter[groupPosition][childPosition], Toast.LENGTH_LONG).show();
flag = "p";
Bundle bundle = new Bundle();
bundle.putString("topic",topic[groupPosition]);
bundle.putString("chapter",chapter[groupPosition][childPosition]);
Intent goHome = new Intent(getApplicationContext(), VideoWeb.class);
goHome.putExtras(bundle);
startActivity(goHome);
}
});
lecvidbtn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplication(), "Topic Lec video is: "+topic[groupPosition]+" and Chapter is "+chapter[groupPosition][childPosition], Toast.LENGTH_LONG).show();
flag = "l";
Bundle bundle = new Bundle();
bundle.putString("topic",topic[groupPosition]);
bundle.putString("chapter",chapter[groupPosition][childPosition]);
Intent goHome = new Intent(getApplicationContext(), VideoWeb.class);
goHome.putExtras(bundle);
startActivity(goHome);
}
});
return lecvidbtn; //My confusion is here. How to capture the return value for any of the image buttons clicked above.?
}
我不認爲你可以做到這一點,因爲在列表視圖只列表項被點擊而不是它的孩子..所有的孩子都不可聚焦.. – ngesh
@sandy,當我有一個圖像按鈕時,我可以得到結果,但是當我添加兩個圖像按鈕時,該方法仍然限制我只使用一個圖像按鈕單擊,其他圖像按鈕不響應。這就是我希望傳遞的回報價值。我需要修理那裏。 – kittu