Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

Android BaseAdapter ListView Button Click to access other activity item

I have BaseAdapter class for listview , two button is in this listview . When click this button ,i want to that open or closing slinding drawer . Full screen my application picture http://tinypic.com/view.php?pic=wtjg2s&s=8#.VFngCvmsXtt

My baseadapter class

public class SCariList extends BaseAdapter{

    NCari cari = new NCari();   
    Context context;
    Activity activity;

    private LayoutInflater inflater;
    private List<NCari> cariList;

    public SCariList(Activity activity , List<NCari> cariler,Context con){

        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

         cariList = cariler;

         context = con;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        View vi = convertView;

        if(convertView == null)
        //  vi = inflater.inflate(R.layout.test_satir, parent,false);

        vi = inflater.inflate(R.layout.test_satir, null);
        final TextView textViewtest = (TextView) vi.findViewById(R.id.test_satir);
        final TextView textView2 = (TextView) vi.findViewById(R.id.test_satir2); //cal???yor

        //Bu ikisini kapalt?k
        final ImageButton btn_gecmis  = (ImageButton) vi.findViewById(R.id.btn_gecmis);
        final ImageButton btn_duzenle = (ImageButton) vi.findViewById(R.id.btn_duzenle);

        /*Burada bir terslik var*/
        final Button btn_gecmis1 = (Button) vi.findViewById(R.id.btn_evrak1);   
        final Button btn_duzenle1 = (Button) vi.findViewById(R.id.btn_gecmis1);

        //Buraya istedi?imiz gibi ekleyebilir.
        NCari nCari = cariList.get(position);
        /*istedi?imiz de?erlerle set ettik*/
        textViewtest.setText(String.valueOf(nCari.getID()));
        textView2.setText(nCari.getAd().toString());

        /*Butona bas?nca SlidingDrawer cal??mas?
         * sdwAlisFatura ad?*/

        /*YEN? EVRAK*/
        btn_gecmis1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                cari.setCariID(Integer.valueOf(textViewtest.getText().toString())); 
                cari.setAd(textView2.getText().toString());

                Intent intent = new Intent(context, SEvrak.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                intent.putExtra("Cari", cari);

                context.startActivity(intent);

            }
        });

        btn_duzenle1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            //  Toast.makeText(context, "Oldu", 10).show();

            }
        });

        return vi;

    }

}

and activity classs

 public class AlisCari extends Activity {

   Context context=this ;

   EditText arama;
   ListView cariListView;
   TextView tvSatir;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alis_cari);

        arama = (EditText) findViewById(R.id.txtAlisFaturaArama);

        cariListView = (ListView) findViewById(R.id.lstAlisSiparisCari);

        CariVeritaban cariVeritaban = new CariVeritaban(getApplicationContext());

        List<NCari> cariler = cariVeritaban.getCariListe();

        SCariList sCariList = new SCariList(AlisCari.this, cariler, context);

        cariListView.setAdapter(sCariList);

        arama.addTextChangedListener(txtizleyici);

    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use this code:

public class SCariList extends BaseAdapter{

    NCari cari = new NCari();   
    Context context;
    Activity activity;

    private LayoutInflater inflater;
    private List<NCari> cariList;

    public SCariList(Activity activity , List<NCari> cariler,Context con){

        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

         cariList = cariler;

         context = con;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        View vi = convertView;

        if(convertView == null)
        //  vi = inflater.inflate(R.layout.test_satir, parent,false);

        vi = inflater.inflate(R.layout.test_satir, null);
        final TextView textViewtest = (TextView) vi.findViewById(R.id.test_satir);
        final TextView textView2 = (TextView) vi.findViewById(R.id.test_satir2); //cal???yor

        //Bu ikisini kapalt?k
        final ImageButton btn_gecmis  = (ImageButton) vi.findViewById(R.id.btn_gecmis);
        final ImageButton btn_duzenle = (ImageButton) vi.findViewById(R.id.btn_duzenle);

        /*Burada bir terslik var*/
        final Button btn_gecmis1 = (Button) vi.findViewById(R.id.btn_evrak1);   
        final Button btn_duzenle1 = (Button) vi.findViewById(R.id.btn_gecmis1);

        //Buraya istedi?imiz gibi ekleyebilir.
        NCari nCari = cariList.get(position);
        /*istedi?imiz de?erlerle set ettik*/
        textViewtest.setText(String.valueOf(nCari.getID()));
        textView2.setText(nCari.getAd().toString());

        /*Butona bas?nca SlidingDrawer cal??mas?
         * sdwAlisFatura ad?*/

        /*YEN? EVRAK*/
        btn_gecmis1.setOnClickListener(new Listener1());

        btn_duzenle1.setOnClickListener(new Listener2());

        return vi;

    }

class Listener1 implements OnClickListener
{
@Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
   cari.setCariID(Integer.valueOf(textViewtest.getText().toString())); 
                cari.setAd(textView2.getText().toString());

                Intent intent = new Intent(context, SEvrak.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                intent.putExtra("Cari", cari);

                context.startActivity(intent);

            }
        });
}
class Listener2 implements OnClickListener
{
@Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            //  Toast.makeText(context, "Oldu", 10).show();

            }
        });
}

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...