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 に答える