0

私はブラジル出身で、ボタンの画像とテキストを含むリストビューがあります。ボタンのリストビューをクリックして、クリックしている行の原因となるビューを取得しようとしています。だから私はこれが私のボタンである行に変更を加えることができます。

何が起こっているのか、そして以下のコードの場合、ボタンをクリックすると、どのボタンのリストでも、彼は常に最初のリスト項目で変更を行い、私は彼にそれぞれの行で変更を加えてもらいたいと思いました。したがって、このリスト

画像---------------------------テキスト-ボタン
画像----------------- ----------テキスト-ボタン
の画像---------------------------テキスト-ボタン
の画像--- ----------------------テキスト-ボタン

ボタンをクリックすると、彼は行の例のテキストを変更するだけです。

画像---------------------------テキスト-ボタン
画像----------------- ---------変更-ボタン<-クリックされた画像
---------------------------テキスト-ボタンの
画像------------ --------------- TEXT--BUTTON

と..

画像---------------------------テキスト-ボタン
画像----------------- ----------テキスト-ボタン
の画像---------------------------テキスト-ボタン
の画像--- ------------------------変更-ボタン<-クリック

それを思い出して、フラグメントリスト内のアダプタを使用しました申し訳ありませんが、私の英語は悪いです!

public class JAdapterList extends BaseAdapter  implements OnClickListener {

    private LayoutInflater mInflater;
    private ArrayList<JItemList> itens;

    public JAdapterList(Context context, ArrayList<JItemList> itens) {
        //Itens que preencheram o listview
        this.itens = itens;
        //responsavel por pegar o Layout do item.
        mInflater = LayoutInflater.from(context);
    }

    public int getCount() {
        return itens.size();
    }

    public JItemList getItem(int position) {
        return itens.get(position);
    }

        public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View view, ViewGroup parent) {
        //Pega o item de acordo com a posção.
        JItemList item = itens.get(position);
        //infla o layout para podermos preencher os dados

        view = mInflater.inflate(R.layout.navlistitem, null);

        ((TextView) view.findViewById(R.id.textListView)).setText(item.getNome());


        ImageButton ib = (ImageButton) view.findViewById(R.id.imageButton1);
        ib.setOnClickListener(this);

        return view;
    }

    @Override
    public void onClick(View v) {

        // TODO Auto-generated method stub


    View vv = v.getRootView();


    ImageView tv = (ImageView) vv.findViewById(R.id.imageView1);
    TextView texto = (TextView) vv.findViewById(R.id.textListView4);
    texto.setText("CHANGE");
    tv.setAnimation(AnimationUtils.loadAnimation(tv.getContext(), R.anim.motion));




    }
}
4

2 に答える 2

5

テキストビューをボタンのタグに設定すると、はるかに簡単になります。このように: getView で:

TextView textView = ((TextView)  view.findViewById(R.id.textListView)).setText(item.getNome());


    ImageButton ib = (ImageButton) view.findViewById(R.id.imageButton1);
    ib.setOnClickListener(this);
     ib.setTag(textView);

onClickListener で:

 public void onClick(View v) {
    TextView texto = (TextView) v.getTag();
    texto.setText("CHANGE");
  }
于 2013-01-28T21:34:47.507 に答える
0

たとえば、checkBox の場合 (残りのビューも同じ): View viewParent = (View)checkBox.getParent();

しかし、もっと簡単にしたい場合は、次の投稿を確認してください: OnItemClick リスナーがカスタム ListView で機能しない

幸運を :)

于 2013-01-28T21:02:34.850 に答える