• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps ListView Help

dgibbiii

Lurker
Mar 4, 2011
1
0
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"
};
}
 
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...
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones