0

这是我以自定义格式显示列表视图的代码。但我的要求是,当我单击任何列表视图项目时,需要显示其进一步的详细信息,但是当我单击它时……它根本没有生效我意味着没有执行 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;

                                            }
                         }
                  }
4

1 回答 1

2

您需要添加

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

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

于 2012-06-11T12:53:25.490 回答