Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old March 4th, 2011, 12:34 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Mar 2011
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default ListView Help

I am new at creating UI Java apps and am trying to create an app that starts with a list of items (ListView) to choose from and then open the corresponding package. I have created the list along with one of the many packages and they both work independently. My problem is I cannot figure out for the life of me how to call the selected "module" from the list. Here is the list code:

package com.constructioncalc.main;

import com.example.squarefeet.*;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ConstructionCalc extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, CALCULATORS));

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

lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, goto selected package
DO SOMETHING HERE
}
});
}

static final String[] CALCULATORS = new String[] {
"Square Feet"
};
}

dgibbiii is offline  
Reply With Quote
sponsored links
Old March 4th, 2011, 05:55 PM   #2 (permalink)
Member
 
Join Date: Dec 2010
Location: Aarhus, Denmark
Posts: 136
 
Device(s): SE Xperia X10
Carrier: Not Provided

Thanks: 2
Thanked 22 Times in 22 Posts
Default

I am not sure I know what you mean when you say call the selected module, but i guess you want to either open a Dialog or a new Activity with the selected modules features?

If so all you need to do is create these Activities and/or Dialogs (see developer.android.com for more on that), and open the right one depending on which item is selected in the list. That item is placed at a certain position in the list, which is given as one of the parameters of the OnItemClickListener.

So if position 0 represents a module which allows a user to read about Tennis then you should have the "DO SOMETHING HERE" start the Tennis Activity if the position == 0...

And so on...
JamTheMan is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:46 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.