質問

I am trying to implement list. Here is start.xml file which have a text box i which i am typing any word and a list of words will open containing this word:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<EditText
    android:id="@+id/start_edit"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="top|left"
    android:ems="10"
    android:hint="Type to search"
    android:paddingLeft="50dp" >

    <requestFocus />
</EditText>

for list view i am using this ListView.xml file:

<ImageView
    android:id="@+id/image_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/abacus_thumbnail"
    android:scaleType="centerCrop" />

<ImageView
    android:id="@+id/imageView_color_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/blue_thumbnail" />

<TextView
    android:id="@+id/title_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/image_list"
    android:layout_marginLeft="20dp"
    android:layout_toRightOf="@+id/image_list"
    android:gravity="center"
    android:text="Abacus"
    android:textColor="#000000"
    android:textSize="30sp"
    android:textStyle="bold"
    android:typeface="sans" />

<TextView
    android:id="@+id/textView_meaning_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/title_list"
    android:layout_below="@+id/title_list"
    android:layout_marginTop="10dp"
    android:text="TextView"
    android:textColor="#000000"
    android:textSize="25sp" />

i am using EfficientAdapetr to convert one View from one to another when my app start the EditBox will be empty and a background image . I have ClickListner on list item when a word is type a list opens and when click on item this word will open. Now problem is that when i click on item of list the background populate with word but listView not remove. on Item click i want to open my background with the word. Here is my code:

    listAdapter = new EfficientAdapter2(this);
    setListAdapter(listAdapter);


private class EfficientAdapter2 extends BaseAdapter implements Filterable,OnItemClickListener {

    private Context context;
    LayoutInflater inflater;

    public EfficientAdapter2(Context context) {

        this.context = context;
        inflater = LayoutInflater.from(context);

    }

    public int getCount() {


        //  if(SearchWordString.isEmpty()==false)
        //  {

        return SearchWordString.size();
        /// }

        //return 0;
    }

    public Object getItem(int position) {

        return position;
    }

    public long getItemId(int position) {

        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder2 holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.ListView, null);
            holder = new viewHolder2();
        //  Log.i("View","is Null");
            convertView.setTag(holder);

        } else {

            //Log.i("View","is not Null");
            holder = (viewHolder2) convertView.getTag();
        }

        holder.word = (TextView) convertView.findViewById(R.id.title_list);
        holder.meaning = (TextView) convertView
                .findViewById(R.id.textView_meaning_list);
        holder.image = (ImageView) convertView
                .findViewById(R.id.image_list);
        holder.image_color = (ImageView) convertView
                .findViewById(R.id.imageView_color_list);
        holder.cell = (RelativeLayout) convertView
                .findViewById(R.id.RelativeLayout_list);









        try {

"functionalty here"

        } catch (IOException e) {

            e.printStackTrace();
        }

        return convertView;
    }

here is onItemClick:

protected void onListItemClick(ListView l, View v, int position, long id) {//////// super.onListItemClick(l, v, position, id);

    //Log.i("Position",""+position);
    changeEverything(position);// here i am converting my ListView to
                                           Start.xml but its on happening

    motherOfIndex = position;








}
役に立ちましたか?

解決

first debug your app and check weather onListItemClick() event firing. this won't fire if you have clickable items in your listView. if that's the case you have to set isClickable=false for all the items in ListView.xml file. in order to dismiss the the listView, you have to set it's visibility to View.GONE

However if you want to popup a suggestion list when something type on a EditText, this is not the best practice to do that. you can use a AutoCompleteTextView and directly set your ListView adapter to it. they it will create a listView for your and will automatically handle the set selected text to the AutoCompleteTextView and will dismiss the listView

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top