2

リストビュー内に編集テキストと保存ボタンがあります。ユーザーが保存ボタンをクリックしたときにテキストをクリアする必要があります。私は次のように試しました

txtDescription.setText("");

しかし、動作しませんでした。なぜそれが機能しないのか誰もが知っていますか?Adapterクラスがアタッチされています

助けてください、よろしくお願いします!!

private class ListAdapters extends ArrayAdapter<ApplicationBean> {
    private ArrayList<ApplicationBean> items;
    private int position;

    public ListAdapters(Context context, int textViewResourceId,
            ArrayList<ApplicationBean> mTitleList) {
        super(context, textViewResourceId, mTitleList);
        this.items = mTitleList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        this.position = position;
        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.applicationlistitem, null);
        }

        final ApplicationBean o = (ApplicationBean) items.get(position);

        if (o != null) {

            txtDescription = (EditText) v
                    .findViewById(R.id.description_text);



            submitButton = (Button) v.findViewById(R.id.submit_btn);
            submitButton.setTag(position);
            submitButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {

                        PostRequest p = new PostRequest(Integer.parseInt(v
                                .getTag().toString()));
                        p.execute();
                }

            });
        }
        return v;
    }

    @Override
    public int getItemViewType(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public int getViewTypeCount() {
        // TODO Auto-generated method stub
        return items.size();
    }

}



private class PostRequest extends AsyncTask<Void, Void, String> {
    ProgressDialog dlgprogress;
    int position;

    public PostRequest(int selectedIndex) {
        position = selectedIndex;
    }

    @Override
    protected void onPostExecute(String result) {
        dlgprogress.dismiss();
        final Dialog dlg = new AlertDialog.Builder(mContext)
                .setTitle("Message")
                .setMessage(result)
                .setPositiveButton("Ok",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {
                                dlgprogress.dismiss();
                                dlgprogress.cancel();
                                txtDescription.setText("");
                            }
                        }).create();
        dlg.show();
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        dlgprogress = ProgressDialog.show(mContext, "", "Please wait");
        // dlgprogress.show(mContext, "", "Please wait");
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(Void... arg0) {
        //do something.............
        //..........................
        dlgprogress.dismiss();
        return rsponse;
    }

}

applicationlistitem.xml

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:background="#FFFFFF">



    <LinearLayout
        android:id="@+id/lineatlayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="DESCRIPTION : "
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000" />

        <EditText
            android:id="@+id/description_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="true"
            android:ems="10"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:inputType="textMultiLine" 
            android:textColor="#000000">
        </EditText>
    </LinearLayout>

    <Button
        android:id="@+id/submit_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SUBMIT" />

   </LinearLayout>
4

3 に答える 3

2

リストビューのカスタムアダプタクラスを維持する

 public View getView(final int position, View convertView, ViewGroup parent)
    {
        View row=null;
        Context context = getApplicationContext();
        LayoutInflater inflater=cntx.getLayoutInflater();
        row=inflater.inflate(R.layout.search_list_item, null);

        EditText txtDescription=    (EditText)row.findViewById(R.id.txtDescription);
        Button Savebtn  =   (Button)row.findViewById(R.id.SaveBtn);

        Savebtn.setOnClickListener(new OnClickListener(){

            public void onClick(View v) 
            {
                txtDescription.setText("");
                // And your additional coding
            }
        });
   }

リストビューのカスタムアダプタを初めて使用する場合は、こちらを確認してください

于 2012-10-31T05:32:23.320 に答える
1

objectボタンビューにTAGとしてanyを設定することもできます。

だからあなたのgetView()方法でこのようにしてください、そして私はそれがうまくいくと思います。

             //EDIT
         txtDescription.setTag(position); // set position to edittext

         submitButton = (Button) v.findViewById(R.id.submit_btn);
         submitButton.setTag(txtDescription); // set the current edittext object 

         submitButton.setOnClickListener(new OnClickListener() {        
                @Override
                public void onClick(View v) {
                       EditText tv = (EditText)v.getTag(); // get edittext object
                       tv.setText("");
                             //Edit
                       PostRequest p = new PostRequest(Integer.parseInt(tv
                                .getTag().toString())); // get position from edittext
                    }
                });

完全なビューを送信するために編集

私はこれをテストしていませんが、機能しない場合は機能すると思います。editextを送信するときに、チェックボックスもコンストラクターに送信します。

class PostTask extends AsyncTask<Void,Void,Void>
{
    CheckBox cb;
    EditText et;
    int pos;
    PostTask(int pos,View view)
    {
        cb = view.findViewById(R.id.cbox1);
        et = view.findViewById(R.id.et1);
        pos = Integer.parseInt(et.getTag().toString());
    }
}

//getViewの変更

submitButton.setOnClickListener(new OnClickListener() {     
            @Override
            public void onClick(View v) {
                   PostRequest p = new PostRequest((View)v.getParent()); // get position from edittext
            }
 });
于 2012-10-31T05:48:52.203 に答える
0

すべてのリストアイテムにeditTextと送信ボタンがありますか?

わかりました。listViewにはビューを変換するシステムがあります...配列のサイズほどビューを作成しませんが、画面にユーザーを表示するのに十分なだけ作成し、スクロール中に好きなように変換を開始します...したがって、1つのeditTextをクリアすると、他の値で埋められていることがわかります...したがって、editText値を保存し、送信ボタンをクリックして削除し、アダプタで行うように、listViewにフィードする別の配列を用意することをお勧めしますこの配列を使用してeditTextのテキストを設定する必要があります。これにより、値がすでに送信されている場合は空になります。

そして、ここにあなたの問題の解決策があります:

リストと同じサイズの配列を作成してみてください。

ArrayList<String> texts = new ArrayList<String>();
for(int i = 0; i < items.size(); i++)
texts.add(“”);

したがって、最初はすべてのeditTextが空になります...次に、カスタムアダプタのgetViewメソッドでそれらを設定します。

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    this.position = position;
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.applicationlistitem, null);
    }

    final ApplicationBean o = (ApplicationBean) items.get(position);

    if (o != null) {

        txtDescription = (EditText) v
                .findViewById(R.id.description_text);

    // you should set your every views’ editText here
    txtDescription.setText(texts.get(position));

    // here you save texts also they changes
    txtDescription.addTextChangedListener({
         @Override
         public void afterTextChanged(Editable s) {
            texts.remove(position);
            texts.add(position, s.toString());
         }

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

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

        submitButton = (Button) v.findViewById(R.id.submit_btn);
        submitButton.setTag(position);
        submitButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
        texts.remove(position);
        texts.add(position, “”);

                    PostRequest p = new PostRequest(Integer.parseInt(v
                            .getTag().toString()));
                    p.execute();
            }

        });
    }
    return v;
}
于 2012-10-31T05:57:06.790 に答える