Hi,
I tried to select an item from the list, but not getting somebody
please help. I struck here for a long time. Actually in this, i am
using Baseadapter. So How can i select. I tried with onItemClick, but
null pointer exception coming..
public class ListQuery extends ListActivity implements
OnItemClickListener {
SQLiteDatabase myDatabase = null;
int size = 20;
String[] iStuffarea = new String[size];
String[] iStuffage = new String[size];
String[] iStuffsex = new String[size];
String[] iStuffheight = new String[size];
String[] iStuffweight = new String[size];
String[] iStuffcity = new String[size];
String[] iStuffcountry = new String[size];
String[] uStuffarea = new String[size];
String[] uStuffage = new String[size];
String[] uStuffsex = new String[size];
String[] uStuffheight = new String[size];
String[] uStuffweight = new String[size];
String[] uStuffcity = new String[size];
String[] uStuffcountry = new String[size];
int count = 0;
ArrayList<String> results = new ArrayList<String>();
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setListAdapter(new SpeechListAdapter(this));
getListView().setOnItemClickListener(this);
}
private class SpeechListAdapter extends BaseAdapter {
public SpeechListAdapter(Context context) {
mContext = context;
try {
myDatabase = mContext.openDatabase("Mobeegal", null);
String myCols[] = {"iStuffAge", "iStuffSex",
"iStuffHeight", "iStuffWeight", "iStuffArea", "iStuffCity",
"iStuffCountry"};
Cursor c = myDatabase.query(false, "IStuff", myCols,
null, null, null, null, null);
String myCols1[] = {"uStuffAgeRange", "uStuffSex",
"uStuffHeightRange", "uStuffWeightRange", "uStuffArea", "uStuffCity",
"uStuffCountry"};
Cursor c1 = myDatabase.query(false, "UStuff", myCols1,
null, null, null, null, null);
int uagecolumn = c1.getColumnIndex("uStuffAgeRange");
int usexcolumn = c1.getColumnIndex("uStuffSex");
int uheightcolumn =
c1.getColumnIndex("uStuffHeightRange");
int uweightcolumn =
c1.getColumnIndex("uStuffWeightRange");
int uareacolumn = c1.getColumnIndex("uStuffArea");
int ucitycolumn = c1.getColumnIndex("uStuffCity");
int ucountrycolumn =
c1.getColumnIndex("uStuffCountry");
int ageColumn = c.getColumnIndex("iStuffAge");
int sexColumn = c.getColumnIndex("iStuffSex");
int heightColumn = c.getColumnIndex("iStuffHeight");
int weightColumn = c.getColumnIndex("iStuffWeight");
int areaColumn = c.getColumnIndex("iStuffArea");
int cityColumn = c.getColumnIndex("iStuffCity");
int countryColumn = c.getColumnIndex("iStuffCountry");
if (c != null) {
count = 0;
if (c.first()) {
do {
String getiage = c.getString(ageColumn);
String getisex = c.getString(sexColumn);
String getiheight =
c.getString(heightColumn);
String getiweight =
c.getString(weightColumn);
String getiarea = c.getString(areaColumn);
String geticity = c.getString(cityColumn);
String geticountry =
c.getString(countryColumn);
iStuffarea[count] = getiarea;
iStuffage[count] = getiage;
iStuffsex[count] = getisex;
iStuffheight[count] = getiheight;
iStuffweight[count] = getiweight;
iStuffcountry[count] = geticountry;
iStuffcity[count] = geticity;
count++;
} while (c.next());
}
}
if (c1 != null) {
count = 0;
if (c1.first()) {
do {
String getuage = c1.getString(uagecolumn);
String getusex = c1.getString(usexcolumn);
String getuheight =
c1.getString(uheightcolumn);
String getuweight =
c1.getString(uweightcolumn);
String getuarea =
c1.getString(uareacolumn);
String getucity =
c1.getString(ucitycolumn);
String getucountry =
c1.getString(ucountrycolumn);
uStuffage[count] = getuage;
uStuffsex[count] = getusex;
uStuffheight[count] = getuheight;
uStuffweight[count] = getuweight;
uStuffarea[count] = getuarea;
uStuffcity[count] = getucity;
uStuffcountry[count] = getucountry;
//results.add("IStuff :" +
iStuffarea[count] + "UStuff :" + uStuffarea[count]);
count++;
} while (c1.next());
}
}
} catch (FileNotFoundException ex) {
//
Logger.getLogger(ListClick.class.getName()).log(Level.SEVERE, null,
ex);
}
}
public int getCount() {
return iStuffarea.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup
parent) {
SpeechView sv;
if (convertView == null) {
sv = new SpeechView(mContext, " Age = " +
iStuffage[position] + " Height = " + iStuffheight[position] + " Weight
= " + iStuffweight[position] + " Area = " + iStuffarea[position] + "
City = " + iStuffcity[position] + " Country = " +
iStuffcountry[position],
" Age Range = " + uStuffage[position] + "
Height Range = " + uStuffheight[position] + " Weight Range= " +
uStuffweight[position] + " Area = " + uStuffarea[position] + " City =
" + uStuffcity[position] + " Country = " + uStuffcountry[position]);
} else {
sv = (SpeechView) convertView;
sv.setTitle(iStuffage[position]);
sv.setDialogue(uStuffarea[position]);
}
return sv;
}
private Context mContext;
public void onItemClick(AdapterView arg0, View arg1, int arg2,
long arg3) {
// Toast.makeText(mContext, "asdasdsa",
Toast.LENGTH_LONG).show();
}
}
private class SpeechView extends LinearLayout {
public SpeechView(Context context, String title, String words)
{
super(context);
this.setOrientation(VERTICAL);
mTitle = new TextView(context);
mTitle.setText("Stuff1 : " + title);
addView(mTitle, new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
mDialogue = new TextView(context);
mDialogue.setText("Stuff2 : " + words);
addView(mDialogue, new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
public void setTitle(String title) {
mTitle.setText(title);
}
public void setDialogue(String words) {
mDialogue.setText(words);
}
private TextView mTitle;
private TextView mDialogue;
}
public void onItemClick(AdapterView parent, View v, int position,
long id) {
SpeechListAdapter obj = new SpeechListAdapter(this);
String selectid = obj.getView(position,v,null).toString();
Toast.makeText(ListQuery.this, selectid,
Toast.LENGTH_LONG).show();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---