简体   繁体   English

您好,我有一个列表视图,其中包含要使用onitemclick方法打开另一个列表的元素列表

[英]hi i have a list view that contains list of elements i want to use onitemclick method to open another list

hi i have a list view that contains list of methods so here i am going to display it's parameters in another list so when i click on list item(method) it has to display it's parameter it can achieved through onitemclick() method i tried but it shows some error 您好,我有一个包含方法列表的列表视图,因此在这里我将在另一个列表中显示它的参数,因此当我单击列表项(方法)时它必须显示它的参数可以通过尝试的onitemclick()方法实现,它显示了一些错误
can any one help please 有人可以帮忙吗

this is my listview.java file 这是我的listview.java文件

public class Listview extends Activity{
private CursorAdapter customAdapter;
private Param databaseHelper;
private static final int ENTER_DATA_REQUEST_CODE = 1;
private ListView listView;     
private static final String TAG = Listview.class.getSimpleName();

private ListView lv;
public static ArrayList<String> your_array_list = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview);
    databaseHelper = new Param(this);                       
   customAdapter = new CursorAdapter (this, databaseHelper.getTripList( Param.DESC), 
   0);    
    listView = (ListView) findViewById(R.id.listView1); 
    listView.setAdapter(customAdapter); 

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long    
 id) {
            Log.d(TAG, "clicked on item: " + position);
        }
    });  


    lv = (ListView) findViewById(R.id.listView1);
     Button backButton=(Button)findViewById(R.id.methodbackbutton1);
     backButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Listview.this.finish();
            }
        });}

  @Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
}

@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1, your_array_list );
    lv.setAdapter(arrayAdapter); 
     try {
      DisplayM.main();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
@Override
public void onBackPressed()
{
    Intent intent3 = new Intent(this, Nextactivity.class);
    startActivity(intent3);
    finish();
 }
@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
}




}

this is my listview.xml file 这是我的listview.xml文件

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textViewMyRecording"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:text="@string/listofMethods"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ListView
    android:id="@+id/listView1"
    android:layout_width="wrap_content"
    android:layout_height="384dp" >

</ListView>

 <Button
    android:id="@+id/methodbackbutton1"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:onClick="onBackPressed"
    android:text="@string/Backtopreviousscreen" />

</LinearLayout>

You are taking the reference of Same ListView resource findViewById(R.id.listView1) in both variable listView & lv. 您在变量listView和lv中都引用了Same ListView资源findViewById(R.id.listView1)。

Second thing, why you are taking Cursor Adapter for your list? 第二件事,为什么要将游标适配器作为列表?

Third thing, what's the purpose of DisplayM.main(); 第三件事,DisplayM.main()的目的是什么?

Fourth thing, you can finish an activity by writing just finish() then why you are writing it like Listview.this.finish(); 第四件事,您可以通过仅编写finish()以及为什么要像Listview.this.finish()那样编写活动来完成活动。 ?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java-我有一个 ArrayList 包含对象,一次出现后我希望将 object 添加到另一个列表 - Java-I have an ArrayList contains objects, after one occurrence I want the object is added to another list 我想从列表视图中删除项目 - I want to delete an item from a list view 我想要一种方法中的两个数组列表 - i want two array list in one method 我在String表的Java中有一个数组列表,我想从这些表中删除空元素和null元素 - I have an array list in java of String tables and I want to delete empty and null elements from those tables 我有一个列表视图。如何将列表视图的点击总数保存到另一个活动文本视图? - I have a list view.how i will save list view total number of click to another activity text view? 如何通过按钮触发列表项的onItemClick? - How can I trigger on onItemClick of a list item from a button? 如何使用 Java 中的合并方法将元素附加到地图中的列表值<Character,List<Integer> &gt;? - How can I use merge method in Java to append elements to the list value in map<Character,List<Integer>>? 我如何在这里使用循环,我想每回合从列表中删除 3 个元素 - How can I use loop here, I want to remove 3 elements from list for every turn 如何验证列表元素是否与另一个列表的顺序相同? - How can I verify that a list elements are in same order of another list or not? 我有两个列表,我想根据 groovy 或 java 中其他列表中的 id 过滤一个列表 - I have two list and i want to filter a list on the basis of id present in other list in groovy or java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM