0

I am very new to Android.

I need to create a list view, where there's a list of items on the left, and clicking on an item opens up a dialog box like thing to show info about the item. Moreover, I want to be able to select these (or check?) items from the list of items, then click on a "Done" button within the same screen to go back to another activity that uses the three selected item. I've tried reading up on the ListView documentation but so far Android hasn't been so intuitive, which is why I'm really held up.

Here's my current code:

public class PlayerList extends ListActivity {

static final String[] PLAYERS = new String[] { "Messi", "Ronaldo", "Drogba", "Wesley"};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // no more this
    // setContentView(R.layout.list_fruit);

    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_view2,PLAYERS));

    ListView listView = getListView();
    listView.setTextFilterEnabled(true);

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // When clicked, show a toast with the TextView text

            // edit this part to be able to show a new screen with info about the player

            Toast.makeText(getApplicationContext(),
            ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });

}

Can you please advise me on how I can 1) create the detailed screen for each item upon a click, 2) be able to check/select items, 3)modify the current code to include 1 & 2.

Thanks!

4

1 回答 1

0

有关信息,您可以将此代码用于对话框,并且可以通过 showSettingsAlert() 调用;在您希望此对话框显示的任何位置。

   public void showSettingsAlert(){
         AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

         // Setting Dialog Title
         alertDialog.setTitle("Title here");

         // Setting Dialog Message
         alertDialog.setMessage("here the information can be display");


         alertDialog.setNegativeButton("OK", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
             dialog.cancel();

             }
         });

         // Showing Alert Message
         alertDialog.show();
     }

另一件事看上下文动作模式。这些链接可能对您有所帮助

http://developer.android.com/guide/topics/ui/menus.html
http://www.vogella.com/articles/AndroidActionBar/

于 2013-07-28T14:38:25.720 回答