我搜索了各种方法,但我似乎无法理解如何让这个东西工作。
我只是想,只要单击 expandablelistview
中的 textview
就可以进入另一个 activity
。但是,我想将用户的点击指定为他们自己的 Activity 。我该怎么做?
长话短说,我只想知道如何处理 textview
的 onclick
?
这是我应该表达 Intent 的代码:
@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) {
//Codes for intent goes in here.
Toast.makeText(finalConvertView.getContext()
, childText.getText()
, Toast.LENGTH_SHORT).show();
}
});
return convertView;
}
非常需要和感谢帮助,请介意帮助我。谢谢。
最佳答案
假设您正在使用项目的arraylist
。您可以使用 childposition
访问列表项。您需要做的就是使用 Intent 传递该元素
看看下面的代码。
private List<ItemDetail> itemList = new ArrayList<ItemDetail>();
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater)
context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.child_row, null);
}
final TextView childText = (TextView) convertView.findViewById(R.id.child_text);
childText.setText(itemList.get(childPosition));
final View finalConvertView = convertView;
childText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Codes for intent goes in here.
Intent intent = new Intent(this,YourActivity.class);
intent.putExtra("datakey", itemList.get(childPosition));
startActivity(intent);
}
});
return convertView;
}
关于android - Intent 点击搜索查看结果的另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43822419/