gpt4 book ai didi

android - ListView setOnClickListener

转载 作者:行者123 更新时间:2023-11-30 02:44:35 26 4
gpt4 key购买 nike

我在 listView 中按下一个列表项。如何从 ListView 项目转到我的另一个 Activity ?请帮助我了解如何解决这个问题。

这是我的代码,如果:

package com.example.list;

import java.util.ArrayList;


public class MainActivity extends ListActivity {

ListView listView;
Context context;
ArrayList prgmList;

public static int[] prgmImage = { R.drawable.a_2, R.drawable.a_2,
R.drawable.a_2, R.drawable.a_2, R.drawable.a_2, R.drawable.a_2,
R.drawable.a_2, R.drawable.a_2

};
public static String[] prgmNameList = { "Let Us C", "c++", "JAVA", "Jsp",
"Microsoft .Net", "Android", "PHP", "Jquery", "JavaScript" };

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
setContentView(R.layout.activity_main);

context = this;
listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new CustomAdapter(this, prgmNameList, prgmImage));

}

最佳答案

你必须实现

OnItemClickListener

到您的 Activity 并将其设置为您的 listView:

public class MainActivity extends Activity implements OnItemClickListener {

...

...

listview.setOnItemClickListener(this);

然后你会得到一个新的方法:

@Override
public void onItemClick(AdapterView<?> arg0, View view, int pos, long id) {

Log.e(TAG, "Pos: " + pos);

}

这里可以得到被舔元素的位置

关于android - ListView setOnClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25294644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com