- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我的 Android 应用程序上的可扩展 ListView 有问题
这是我的代码
package proyek.akhir;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.Toast;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.TextView;
public class list_tempat extends Activity {
private List<String> groupData;
private List<List<String>> childrenData;
static String asalfromList ;
protected static final Object[] String = null;
static String l1 ;
private void loadData() {
groupData = new ArrayList<String>();
groupData.add("Group 1");
groupData.add("Group 2");
groupData.add("Group 3");
childrenData = new ArrayList<List<String>>();
List<String> sub1 = new ArrayList<String>();
sub1.add("G1 Item 1");
sub1.add("G1 Item 2");
childrenData.add(sub1);
List<String> sub2 = new ArrayList<String>();
sub2.add("G2 Item 1");
sub2.add("G2 Item 2");
sub2.add("G2 Item 3");
sub2.add("G2 Item 4");
childrenData.add(sub2);
List<String> sub3 = new ArrayList<String>();
sub3.add("G3 Item 1");
sub3.add("G3 Item 2");
sub3.add("G3 Item 3");
sub3.add("G3 Item 4");
sub3.add("G3 Item 5");
childrenData.add(sub3);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.expandable_list_view);
l1 = "l1";
loadData();
ExpandableListView expandableListView = (ExpandableListView)findViewById(R.id.expandable_list_view);
expandableListView.setAdapter(new ExpandableAdapter());
expandableListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View clickedView, int groupPosition, long groupId) {
return false;
}
});
expandableListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView expandablelistview,
View clickedView, int groupPosition, int childPosition, long childId) {
Intent i = getIntent();
//asalfromList =(String) ((TextView) view).getText();
Intent intent = new Intent(list_tempat.this, ruteangkot.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("l1", String);
intent.putExtra("textAsal",asalfromList );
if (i.getStringExtra("tujuan") != null){
intent.putExtra("textTujuan",list_tempat2.tujuanfromList );
System.out.println("adaan");
}else{
System.out.println("eweh");
intent.putExtra("textTujuan","");
}
menuutama.mu = "";
list_tempat2.l2 = "";
startActivity(intent);
finish();
System.out.println("wkwkwk");
showMessage("hahasu" + ((TextView)clickedView).getText());
return false;
}
});
expandableListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
}
});
expandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
}
});
}
private class ExpandableAdapter extends BaseExpandableListAdapter {
@Override
public Object getChild(int groupPosition, int childPosition) {
return childrenData.get(groupPosition).get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
TextView text = null;
if (convertView != null) {
text = (TextView)convertView;
text.setText(childrenData.get(groupPosition).get(childPosition));
} else {
text = createView(childrenData.get(groupPosition).get(childPosition));
}
return text;
}
@Override
public int getChildrenCount(int groupPosition) {
return childrenData.get(groupPosition).size();
}
@Override
public Object getGroup(int groupPosition) {
return groupData.get(groupPosition);
}
@Override
public int getGroupCount() {
return groupData.size();
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
TextView text = null;
if (convertView != null) {
text = (TextView)convertView;
text.setText(groupData.get(groupPosition));
} else {
text = createView(groupData.get(groupPosition));
}
return text;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
private TextView createView(String content) {
AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 38);
TextView text = new TextView(list_tempat.this);
text.setLayoutParams(layoutParams);
text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
text.setPadding(40, 0, 0, 0);
text.setText(content);
return text;
}
}
private void showMessage(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
}
expandableListView.setOnChildClickListener 不起作用我想从那个子 ListView 中获取数据,任何人都可以帮助我吗?谢谢
最佳答案
您必须激活您的 child 是可选择的!为此,在您的(覆盖)isChildSelectable 中返回 true类方法ExpandableListAdapter .
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
关于android - ExpandableListView OnChildClickListener 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11529472/
我有一个可扩展的 ListView ,当我点击一行时,它会触发 onChildClick 或 onGroupClick,具体取决于我点击的是子项还是组。 如果我在 xml 布局文件中添加可点击的内容(
我是安卓新手。 我在使用 ExpandableListViewAdapter 时遇到了问题。 当我点击编辑文本框时,onChildClickListener 不工作。 我的问题是它是否适用于编辑文本框
我有一个 ExpandableListView,一切正常。我在每个子行中都有一个复选框,当我点击一个子行时,我想切换它,如下所示: expandableListView.setOnChildClick
适配器 public class ExpandableListAdapter extends BaseExpandableListAdapter { private Context mCo
我的 Android 应用程序上的可扩展 ListView 有问题 这是我的代码 package proyek.akhir; import android.app.ListActivity; impo
我在 ExpandableListView 中有一个包含 2 个 child 的组,我想为点击的 child 的名字设置组名。 如何访问在 getGroupView() 方法中生成的 TextView
我有一个如下所示的 BaseExpandableListAdapter: public View getChildView(final int groupPosition, final int chi
我不知道这段代码有什么问题,我的 onChildClickListener() 没有被调用 我看到一些答案,他们说覆盖 isChildSelected 并返回 true;我也试过了,但仍然没有被调用。
为什么没有打印日志?所有其他人的日志都在工作,但 child 不工作。 确实出现了 TextView 的日志,但是当我使用编辑文本时,它不起作用。 为什么会这样?我哪里错了? ExpandableLi
通过单击一个按钮,我会出现一个对话框,其布局中有一个 ExpandableListView,并填充了复选框: button.setOnClickListener(new View.OnClickLis
我有一个 listView 和 sublistView 项目,我提到了 Using lists in Android (15.2. ExpandableListView 示例)。 我可以通过 Toas
我在使可扩展 ListView 的点击监听器正常工作时遇到问题。我是否正确实现了这一点? 代码: elv = getExpandableListView(); // Set up the adapte
我有关于 onChildClickListener 的代码,如下面的代码 fragment OnChildClickListener occl = new OnChildClickListener()
我有一个动态生成的可扩展 ListView ,子列表包含另一组值,我需要在子列表上设置一个 onChildClickListener,以便通过数据中保存的特定 URL 传递 Web Intent 每个
我是一名优秀的程序员,十分优秀!