0

次のアクティビティでデータのカスタム リストを変更したいと考えています。私を助けてください。を試しnotifysetdatachanged()ましたが、リストは同じままです。リスト データを更新したい。

  1. まず、データを保存してリストに表示します
  2. 次に、listActivity でインテントを使用してデータを次のアクティビティに渡しました
  3. 次に、次のアクティビティで更新メソッドを使用します
  4. 今ボタンをクリックして、次のアクティビティの変更に従ってリストを更新したい

カスタム アダプタのコードは次のとおりです。

public class CustomAdapter extends ArrayAdapter<Newd> {
    Context context; 
    int layoutResourceId;    
    static Newd data[];
    public BookHolder holder = null;
    public CustomAdapter(Context context, int textViewResourceId,Newd[] objects) {
        super(context, textViewResourceId, objects);
        this.layoutResourceId = textViewResourceId;
        this.context = context;
        CustomAdapter.data = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        //BookHolder holder = null;

        if(row == null) {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new BookHolder();
            holder.name2= (TextView)row.findViewById(R.id.cname);
            //holder.eml2 = (TextView)row.findViewById(R.id.eml1);
            holder.phn2 = (TextView)row.findViewById(R.id.cphno);

            row.setTag(holder);
        }
        else {
            holder = (BookHolder)row.getTag();
        }

        Newd book_detail = data[position];

        holder.name2.setText(book_detail.name);
        //holder.eml2.setText(book_detail.email);
        holder.phn2.setText(String.valueOf(book_detail.phno));
        System.out.println("name " + book_detail.name + "......." + book_detail.getName() + "name...." + "email " + "phoo" + book_detail.phno );

        return row;
    }

    static class BookHolder {

        TextView name2;
        //TextView eml2;
        TextView phn2;
    }
}

リスト アクティビティの場合:

public class Showdata extends Activity {
    ListView lv;
    String nms,emlss;
    int phns,id11,id1;
    Newd data1[]=null;
    DataHelper dh;
    SharedPreferences pref;
    ArrayList<Newd>data=new ArrayList<Newd>();
    public ArrayList<Integer>phone = new ArrayList<Integer>();
    public ArrayList<String> name = new ArrayList<String>();
    public ArrayList<String> email = new ArrayList<String>();
    public ArrayList<Integer> userid = new ArrayList<Integer>();

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

        dh=new DataHelper(getApplicationContext());
        pref = getSharedPreferences("UID",
                                    Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
        editor.putInt("ID", id1);
        editor.commit();
        System.out.println("id in intent  "  +id1);

        //System.out.println("idssss"   +id1);
        dh.open();
        data=dh.getdata();
        dh.close();

        System.out.println("data .." +data);

        if(data.isEmpty()) {

        }

        else {
            for (int i = 0; i < data.size(); i++) {
                Newd r = data.get(i);
                id11=r.getId();
                nms=r.getName();
                //emlss=r.getEmail();
                phns= r.getPhno();
                //total=r.getSeats();
                System.out.println("list of booking dates  ........" + nms+ "..........u iddd" +phns  +"srno" +emlss);

                userid.add(id11);
                name.add(nms);
                email.add(emlss);
                phone.add(phns);
                System.out.println("list of booking dates1  ........" + nms + "..........u iddd" + phns + "srno" + emlss);
            }

            data1=new Newd[name.size()];

            for (int i = 0; i < name.size(); i++) {
                // srn=srno.get(i);
                int id2=userid.get(i);

                String nm1=name.get(i);
                String eml1=email.get(i);
                int phn1=phone.get(i);

                data1[i]=new Newd(id2,nm1, phn1);
                System.out.println("srno...???"  +id2);
            }
        }

        lv=(ListView) findViewById(R.id.slist);

        final CustomAdapter adapter=new CustomAdapter(Showdata.this, R.layout.custm, data1);
        //lv.add
        lv.setAdapter(adapter);
        System.gc();
        adapter.notifyDataSetChanged();
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position,
                    long id) {
                // TODO Auto-generated method stub
                //Cursor    cr= (Cursor) parent.getItemAtPosition(position);
                // updateList();

                TextView t1=(TextView) findViewById(R.id.cname);
                TextView t2=(TextView) findViewById(R.id.cphno);
                // v=(View)parent.getItemAtPosition(position);
                String unam=t1.getText().toString();

                int phnu=Integer.valueOf(t2.getText().toString());

                Intent it=new Intent(Showdata.this,UpdateData.class);
                it.putExtra("unam",unam);
                it.putExtra("phnu", phnu);
                System.out.println("namesssss"  +unam  + "ph"   +phnu);
                startActivity(it);  
                //    lv.getAdapter().noti  
            }
        }); 
    }
}

次のアクティビティ:

public class UpdateData extends Activity {

    Button update,delete;
    EditText uname,uphn;
    SharedPreferences pref;
    DataHelper dh;
    Cursor cr;
    int idd;
    CustomAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.updatedata);
        update=(Button) findViewById(R.id.usubmit);
        delete=(Button) findViewById(R.id.uBack);
        uname=(EditText) findViewById(R.id.uname);
        uphn=(EditText) findViewById(R.id.uphono);
        pref = getSharedPreferences("UID",
                                    Context.MODE_PRIVATE);
        idd=pref.getInt("ID", 0);
        dh=new DataHelper(getApplicationContext());
        Intent it=getIntent();
        uname.setText(it.getStringExtra("unam"));
        uphn.setText(String.valueOf(it.getIntExtra("phnu", 0)));
        //    System.out.println("getintent"  +name);
        update.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String unames=uname.getText().toString();
                int uphns=Integer.valueOf(uphn.getText().toString());
                dh.open();
                dh.updateValues(idd,unames, uphns);
                dh.close();
                //updateList();

                System.out.println("updateddd"  +unames  +";;;;;;;;;;;;" +uphns);
                Intent up=new Intent(UpdateData.this,Showdata.class);
                startActivity(up);
                //adapter.notifyDataSetChanged();
            }
        });
    }
}
4

0 に答える 0