Listview with Details

后端 未结 4 1847
予麋鹿
予麋鹿 2021-01-17 02:05

i have a Listview which displays list of clients, i have added an onClickListner to Listview so that i can get the detailed information of clicked client.

Li         


        
相关标签:
4条回答
  • 2021-01-17 02:49
    ListView l = (ListView) findViewById(R.id.jl);
    l.setOnItemClickListener(new OnItemClickListener() {
                             @Override
                             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                 ClientListView j = JList.get(position);
                                 Intent intent = new Intent(this, SecondActivity.class);
                                 intent.putExtra("Keyname", j);
                                 startActivity(intent);
                             }
                         }
    );
    }
    

    You can get the intent value in another activity.

    0 讨论(0)
  • 2021-01-17 02:51

    If I have understood, you want to send some information to another activity to display this information.

    You can have a look to the "Intent" in Android. It's used to start a component like an activity and can carry information to this new activity to start.

    Intent i = new Intent(ActivityA.this, ActivityB.class);
    i.putExtra("CUSTOMER_INFO", customer.getName());
    startActivity(i);
    

    Note: If you want to pass a custom object between activities, like for instance a List of custom object :

    List<'CustomObject'>
    

    Your custom object class have to implement Parcelable.

    0 讨论(0)
  • 2021-01-17 02:56

    Use ths code:

    l.setOnItemClickListener(new OnItemClickListener() {
    
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                ClientListView j = JList.get(position);
                String mess = "you clicked position " + position + " With Name " + j.GetClientName();
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityName.this);//Your activity name
    
        // set title
        alertDialogBuilder.setTitle("Hello!");
    
        // set dialog message
        alertDialogBuilder.setMessage(mess)
                .setCancelable(false)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                    }
                });
    
        // create alert dialog
        AlertDialog alertDialog = alertDialogBuilder.create();
    
        // show it
        alertDialog.show();
            }
        });
    

    Hope this will work..

    0 讨论(0)
  • 2021-01-17 03:03

    If you want to pass Client Name which you are displaying in list, you can get id from adapter and use it.

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
            String clientName= (String) ((TextView) view
                    .findViewById(R.id.client_name)).getText();
            Intent intent = new Intent(this, NextActivity.class);
              intent.putExtra("client", clientName);
                startActivity(intent);
    
            }
        } 
    }
    
    0 讨论(0)
提交回复
热议问题