gpt4 book ai didi

java - 设置项目单击监听器事件没有受到影响吗?

转载 作者:行者123 更新时间:2023-12-02 07:45:12 25 4
gpt4 key购买 nike

这是我以自定义格式显示 ListView 的代码。但我的要求是,当我单击 ListView 的任何项目时,需要显示其更多详细信息,但当我单击它时......它根本不显示生效我的意思是没有执行 setonitemclicklictener 事件....我请求请查看上面给出的我的代码....感谢大家

package com.hands;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Passengers extends Activity implements OnClickListener{
ListView lview3;
Button btn;
int textlength = 0;
ArrayList<String> text_sort = new ArrayList<String>();
ArrayList<Integer> image_sort = new ArrayList<Integer>();
ArrayList<String> text_sort2 = new ArrayList<String>();
EditText edittext;
private static String month[] = {"kareem","Saleem","Imran","Anwar","Shahid",
"Raheem","Afzal","Nazeer","Ahmed"};

private static String desc[] = {"ssagi123,Indian","ssagi1234,Indian","ssagi1235,Indian",
"ssagi1236,Indian","ssagi1237,Indian","ssagi1238,Indian","ssagi1239,Indian",
"ssagi12310,Indian","ssagi123411,Indian","Month - 10"};
int[] image = { R.drawable.user2, R.drawable.user2, R.drawable.user2,
R.drawable.user2, R.drawable.user2, R.drawable.user2, R.drawable.user2,
R.drawable.user2, R.drawable.user2, R.drawable.user2 };

/* private static String bstatus[] = {"no status","no status","no status","no status","no status",
"no status","no status","no status","no status"};

*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.passengers);
System.out.println("****1");
btn=(Button)findViewById(R.id.psnbutt1);
btn.setOnClickListener(this);
edittext = (EditText) findViewById(R.id.search_mycontact);
lview3 = (ListView) findViewById(R.id.listView3);
System.out.println("****2");
lview3.setAdapter(new ListViewCustomAdapter(image, month, desc));

edittext.addTextChangedListener(new TextWatcher()
{

public void afterTextChanged(Editable s)
{

}

public void beforeTextChanged(CharSequence s, int start,
int count, int after)
{

}
public void onTextChanged(CharSequence s, int start,
int before, int count)
{

textlength = edittext.getText().length();
text_sort.clear();
image_sort.clear();
text_sort2.clear();

for (int i = 0; i < month.length; i++)
{
if (textlength <= month[i].length())
{
if (edittext.getText().toString().
equalsIgnoreCase((String) month[i].subSequence(0, textlength)))
{
text_sort.add(month[i]);
image_sort.add(image[i]);
text_sort2.add(desc[i]);
}
}
}

System.out.println("****3");
lview3.setAdapter(new ListViewCustomAdapter(image_sort, text_sort, text_sort2));
}
});
System.out.println("****4");

lview3.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("****5");

// Object listItem = lview3.getItemAtPosition(position);
//String keyword=listItem.toString();
// Toast.makeText(getApplicationContext(), "you are selected"+keyword, Toast.LENGTH_LONG).show();


}
});

}

class ListViewCustomAdapter extends BaseAdapter
{
String[] title;
String[] description;
int[] number;
Activity context;
LayoutInflater inflater;

ListViewCustomAdapter()
{

}
ListViewCustomAdapter(int[] image, String[] month, String[] desc)
{
title = month;
description=desc;
number=image;

}
ListViewCustomAdapter(ArrayList<Integer> image,ArrayList<String> month, ArrayList<String> desc)
{
title = new String[month.size()];
description=new String[desc.size()];

number = new int[image.size()];

for(int i=0;i<month.size();i++)
{
title[i] = month.get(i);
description[i]=desc.get(i);
number[i] = image.get(i);

}

}



@Override
public int getCount() {
// TODO Auto-generated method stub
return title.length;
}


@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row=convertView;
row = inflater.inflate(R.layout.listitem_row2, parent, false);
TextView textview = (TextView) row.findViewById(R.id.txtViewTitle);
TextView textview1 = (TextView) row.findViewById(R.id.txtViewDescription);
System.out.println("before list row statement");
//final ListView lview3=(ListView) row.findViewById(R.id.listView3);
// final ListView lview3=(ListView)findViewById(R.id.listView3);
System.out.println("after list row statement");
ImageView imageview = (ImageView) row.findViewById(R.id.imgViewLogo);
textview.setText(title[position]);
textview1.setText(description[position]);
imageview.setImageResource(number[position]);

/*lview3.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {


Object listItem = lview3.getItemAtPosition(position);
String keyword=listItem.toString();
Toast.makeText(getApplicationContext(), "you are selected"+keyword, Toast.LENGTH_LONG).show();


}
});

*/
return (row);
}
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.psnbutt1:
Intent i = new Intent(this, NewhapploginActivity.class);
startActivity(i);
break;

}
}
}

最佳答案

您需要添加

android:focusable="false"
android:focusableInTouchMode="false"

到您的row.xml的所有 View 。因为在自定义ListView中,因为它上面的 View 具有焦点,所以ListView无法使其焦点工作。

关于java - 设置项目单击监听器事件没有受到影响吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10980417/

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