Listview with Details

2019-02-20 18:38发布

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.

ListView l = (ListView) findViewById(R.id.jl);
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                             @Override
                             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                 ClientListView j = JList.get(position);
                                 String mess = "you clicked position " + position + " With Name " + j.GetClientName();
                                 Toast.makeText(Home.this,mess,Toast.LENGTH_LONG).show();
                             }
                         }


);
}

i want to display information but not in toast, i will prefer some activity,fragment or some popup king of thing.

can anybody help?

4条回答
Juvenile、少年°
2楼-- · 2019-02-20 19:02

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.

查看更多
闹够了就滚
3楼-- · 2019-02-20 19:08

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..

查看更多
叛逆
4楼-- · 2019-02-20 19:10

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);

        }
    } 
}
查看更多
Fickle 薄情
5楼-- · 2019-02-20 19:23
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.

查看更多
登录 后发表回答