現在我只想每當點擊expadablelistadapter 時它就會轉到另一個acitvity。我如何確定它被點擊了哪一個?我全部都是在android新手,希望有人能幫助我。我試圖在搜索結果中設置一個onclick方法
這是代碼到我的listadapter
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private String container;
private ArrayList<ParentRow> parentRowList;
private ArrayList<ParentRow> originalList;
public MyExpandableListAdapter(Context context
, ArrayList<ParentRow> originalList) {
this.context = context;
this.parentRowList = new ArrayList<>();
this.parentRowList.addAll(originalList);
this.originalList = new ArrayList<>();
this.originalList.addAll(originalList);
}
@Override
public int getGroupCount() {
return parentRowList.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return parentRowList.get(groupPosition).getChildList().size();
}
@Override
public Object getGroup(int groupPosition) {
return parentRowList.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return parentRowList.get(groupPosition).getChildList().get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ParentRow parentRow = (ParentRow) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.parent_row, null);
}
TextView heading = (TextView) convertView.findViewById(R.id.parent_text);
heading.setText(parentRow.getName().trim());
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildRow childRow = (ChildRow) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater)
context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.child_row, null);
}
ImageView childIcon = (ImageView) convertView.findViewById(R.id.child_icon);
childIcon.setImageResource(childRow.getIcon());
final TextView childText = (TextView) convertView.findViewById(R.id.child_text);
childText.setText(childRow.getText().trim());
final View finalConvertView = convertView;
childText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(finalConvertView.getContext()
, childText.getText()
, Toast.LENGTH_SHORT).show();
}
});
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public void filterData(String query) {
query = query.toLowerCase();
parentRowList.clear();
if (query.isEmpty()) {
parentRowList.addAll(originalList);
}
else {
for (ParentRow parentRow : originalList) {
ArrayList<ChildRow> childList = parentRow.getChildList();
ArrayList<ChildRow> newList = new ArrayList<ChildRow>();
for (ChildRow childRow: childList) {
if (childRow.getText().toLowerCase().contains(query)) {
newList.add(childRow);
}
} // end for (com.example.user.searchviewexpandablelistview.ChildRow childRow: childList)
if (newList.size() > 0) {
ParentRow nParentRow = new ParentRow(parentRow.getName(), newList);
parentRowList.add(nParentRow);
}
} // end or (com.example.user.searchviewexpandablelistview.ParentRow parentRow : originalList)
} // end else
notifyDataSetChanged();
}
}的代碼
這是我的onclick功能假設是我的代碼的一部分,我想補充和意圖其他活動我怎麼能實現它?
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildRow childRow = (ChildRow) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater)
context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.child_row, null);
}
ImageView childIcon = (ImageView) convertView.findViewById(R.id.child_icon);
childIcon.setImageResource(childRow.getIcon());
final TextView childText = (TextView) convertView.findViewById(R.id.child_text);
childText.setText(childRow.getText().trim());
final View finalConvertView = convertView;
childText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(finalConvertView.getContext()
, childText.getText()
, Toast.LENGTH_SHORT).show();
}
});
return convertView;
}
你介意解釋什麼是代碼的行會怎麼辦? –
好的等待我會更新我的答案 –
好的。謝謝先生。 –