View inside toast - android

I want to make a toast in which I have put EditText and a button ..but I can't type anything inside EditText neither I can click the button how to write inside EditText that viewed by the toast..
public class MainActivity extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button New=(Button)findViewById(R.id.button1);
Button save=(Button)findViewById(R.id.button3);
EditText ed1=(EditText)findViewById(R.id.editText1);
final Toast t=new Toast(getApplicationContext());
New.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ListView l=new ListView(getApplication());
l.setAdapter(new badp(getApplicationContext()));
t.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
t.setView(l);
t.setDuration(Toast.LENGTH_LONG);
t.show();
}
});
}
public class badp extends BaseAdapter
{
Context context;
private badp(Context context) {
// TODO Auto-generated constructor stub
this.context=context;
}
public int getCount() {
// TODO Auto-generated method stub
return 1;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LinearLayout l=new LinearLayout(context);
Button b1=new Button(context);
b1.setText("Save");
EditText ed=new EditText(context);
ed.setGravity(Gravity.CENTER);
// LayoutParams lparams = new LayoutParams();
// ed.setLayoutParams(lparams);
ed.setWidth(5);
ed.setEms(10);
l.addView(ed);
l.addView(b1);
return l;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}

You should probably use a Dialog instead of a Toast.
Dialog is designed for more interactive pop-ups, where-as a toast is really designed to display a quick text message.

I really don't think you should use a toast for this kind of user interface. If you look at the documentation it says:
A toast notification is a message that pops up on the surface of the window. It only fills the amount of space required for the message and the user's current activity remains visible and interactive. The notification automatically fades in and out, and does not accept interaction events.
Toast Notifications
What you want is probably a Dialog

Related

Android dynamic listview added position

Hi I am working with android listview.I want to create a dynamic list view in which user can add data dynamically to listview .So far its works fine. Now my problem is my contets are added at start position of listview .I want to add the added contents at last position of list view (like adding comments in facebook post). Is it possible to make ?? Please help me .Thanks in advance :)
MY activity class
public class MainActivity extends Activity {
private EditText etInput;
private Button btnAdd;
private ListView lvItem;
private ArrayList<String> itemArrey;
private ArrayAdapter<String> itemAdapter;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpView();
}
private void setUpView() {
// TODO Auto-generated method stub
etInput = (EditText)this.findViewById(R.id.editText_input);
btnAdd = (Button)this.findViewById(R.id.button_add);
lvItem = (ListView)this.findViewById(R.id.listView_items);
itemArrey = new ArrayList<String>();
itemArrey.clear();
itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,itemArrey);
lvItem.setAdapter(itemAdapter);
btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
addItemList();
}
});
etInput.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_ENTER) {
addItemList();
}
return true;
}
});
}
protected void addItemList() {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
if (isInputValid(etInput)) {
itemArrey.add(0,etInput.getText().toString());
etInput.setText("");
itemAdapter.notifyDataSetChanged();
}
}
protected boolean isInputValid(EditText etInput2) {
// TODO Auto-generatd method stub
if (etInput2.getText().toString().trim().length()<1) {
etInput2.setError("Please Enter Item");
return false;
} else {
return true;
}
}
}
Remove position from
itemArrey.add(0,etInput.getText().toString()); // Position=0
Try this way.
itemArrey.add(etInput.getText().toString());
that directly add your string at the end.
You are specifying position to add new element to. Just avoid using position and new item will be added at the end of list.
itemArrey.add( etInput.getText().toString() );
Further more, you might also like to scroll down to this newly added item. So you can use these in xml
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
or use setSelection() to do so like -
lvItem.setSelection(countOfItems-1);

Return last element of listView and set it into text view - falls on NullPointerException

Please help me with little thing that make me crazy
I’m trying to set text in a textview that is the last element of a dynamic Array.
I add a function inside my Adapter that return the last element of the array.
I’m coming back to the Main Activity where I’d like to show the text and during time it falls at “nullpointerexception”.
Please help
Here is my code:
public class MainActivity extends Activity implements OnClickListener{
private static Context mContext;
public Button mExit, mHistory, mRating;
public TextView mSignal;
HistoryAdapt myLastItem;
List<HistoryItems> m_myLastItem;
#SuppressWarnings("unchecked")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MainActivity.mContext=getApplicationContext();
mExit=(Button)findViewById(R.id.ExitButton);
mExit.setOnClickListener(this);
mHistory=(Button)findViewById(R.id.HistoryButton);
mHistory.setOnClickListener(this);
mRating=(Button)findViewById(R.id.RateButton);
mRating.setOnClickListener(this);
mSignal=(TextView)findViewById(R.id.SignalOfTheDayTV);
//### SET LAST ELEMENT INTO TEXTVIEW
m_myLastItem = new ArrayList<HistoryItems>();
myLastItem=new HistoryAdapt(mContext, m_myLastItem );
m_myLastItem= (List<HistoryItems>) myLastItem.getLastElement();
mSignal.setText(( (HistoryItems) m_myLastItem).getTitle());
// AppRater.app_launched(this);
// AppRater.showRateDialog(this, null);
//Get a Tracker (should auto-report)
((AppManager) getApplication()).getTracker(AppManager.TrackerName.APP_TRACKER);
}//oncreate
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public static Context getAppContext(){
return MainActivity.mContext;
}
public void ExitState(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("You're about to quit Signals4Trading");
builder.setIcon(R.drawable.five);
//builder.setMessage("Your device has been registered successfully. You'll receive signals very soon.");
builder.setMessage("Are you sure you want to quit?");
builder.setCancelable(false);//can't click on the background of the activity
builder.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"See you soon", Toast.LENGTH_LONG).show();
finish();
}//OnClickListener PositiveButton
});//anonymous class PositiveButton
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"Enjoy your visit", Toast.LENGTH_LONG).show();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}//ExitState
public void goToHistoryActivity(){
Intent intent = new Intent(MainActivity.this, HistoryAct.class );
startActivity(intent);
}
public void rateApp(){
Intent intent = new Intent(MainActivity.this, Rate.class);
startActivity(intent);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.ExitButton:
ExitState();
break;
case R.id.HistoryButton:
goToHistoryActivity();
break;
case R.id.RateButton:
rateApp();
break;
}
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
//Get an Analytics tracker to report app starts & uncaught exceptions etc.
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
//Stop the analytics tracking
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
}//MainActivity
**Adapter:**
package com.Signals4Trading.push.android;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class HistoryAdapt extends BaseAdapter {
private final List<HistoryItems>items;
private final Context context;
public HistoryAdapt(Context context,List<HistoryItems>items){
this.context=context;
this.items=items;
}//constructor
#Override
public int getCount() {
// TODO Auto-generated method stub
return items.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return items.get(position);
}
#Override
public long getItemId(int id) {
// TODO Auto-generated method stub
return id;
}
//###FUNCTION THAT RETURN LAST ELEMENT
public HistoryItems getLastElement(){
HistoryItems lastItem = items.get(items.size());
if(items!=null && !items.isEmpty()){
lastItem = items.get(items.size()-1);
}
return lastItem;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null) {
convertView = View.inflate(context, R.layout.historyitems, null);
holder = new ViewHolder();
holder.itemTitle = (TextView) convertView.findViewById(R.id.itemTitleTV);
holder.itemDate=(TextView) convertView.findViewById(R.id.itemDateTV);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.itemTitle.setText(items.get(position).getTitle());
holder.itemDate.setText(items.get(position).getDate());
return convertView;
}
class ViewHolder {
TextView itemTitle;
TextView itemDate;
}
}
//HistoryAdapt
you are getting this error because you have never intialized the object of your adapter class
HistoryAdapt in requires a context and and list to pass into it ,as defined in your constructor
This may be because Listitems is still referencing to null object. Have you called HistoryAdapt(context,items) constructor before calling
HistoryItems l_myLastItem= (HistoryItems) myLastItem.getLastElement(0);
?
Do as Haresh Chhelana said
public HistoryItems getLastElement(){
return items.get(items.size()-1);
}
the reason you are getting null pointer exception is because your list has not been initialized so it is referencing null. To get rid of this error you should first initialize your ArrayList then populate it as
//### SET LAST ELEMENT INTO TEXTVIEW
m_myListItem = new ArrayList();
//then add some data to arrayList for eg:
for (i=1;i<=10;i++){
m_myListItem.add(new HistoryItem().setTitle("title " + i));
}
myLastItem=new HistoryAdapt(mContext, m_myListItem ); //this should be m_myListItem not m_myLastItem
m_myLastItem= myLastItem.getLastElement();// m_myLastItem should be of type HistoryItem as HistoryItem m_myLastItem not List<HistoryItems> m_myLastItem
mSignal.setText(m_myLastItem.getTitle());
P.S. please have a look at your variable naming convention
No need to pass last item index instead directly get index from adapter list size.
public HistoryItems getLastElement(){
return items.get(items.size()-1);
}

Delete a LinearLayout on long press event

I am creating a LinearLayout dynamically. I need to delete the LinearLayout on LongPress event.
My code :
public void addTileView(View v) {
_parentLayout = (LinearLayout) findViewById(R.id.gridCont);
View child = getLayoutInflater().inflate(R.layout.customtileview,null);
((TextView)child.findViewById(R.id.tileText)).setText("Tile View :"+_tileViewCount++);
_parentLayout.addView(child);
_parentLayout.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Delete", Toast.LENGTH_SHORT).show();
return true;
}
});
}
How to do this ?
try this,
_parentLayout.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Delete", Toast.LENGTH_SHORT).show();
parentLayout.removeAllViews();
return true;
}
});
Its better to remove the view which you added in the parent .
Say Parent layout is the main layout and child layout is the one which you want to remove.
You should try
parent_layout.removeView(child_layout);
removeAllViews() - will remove all the views inside the view , but not the main view .
Please refer to ViewGroup
ViewGroup vg = (ViewGroup)(myView.getParent());
vg.removeView(myView);
Alternatively , You can make the visibility of your view to Visible.GONE , and then make it visible when required.
This works for me.
public void addTileView(View v) {
_parentLayout = (LinearLayout) findViewById(R.id.gridCont);
child = getLayoutInflater().inflate(R.layout.customtileview,null);
((TextView)child.findViewById(R.id.tileText)).setText("Tile View :"+_tileViewCount++);
_parentLayout.addView(child);
child.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Delete", Toast.LENGTH_SHORT).show();
_parentLayout.removeView(v);
return true;
}
});
}
Thanks

Android: TabActivity/TabHost with ActivityGroup : Error occurs when creating PreferenceActivity Dialog and Dialog from click button on Custom Listview

I implement a TabActivity (TabHost) with ActivityGroup based on this website http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html
I have 2 questions about implement this.
First question, Using TabActivity with PreferenceActivity, error occurs when I click an preference item to make a preference dialog.
08-10 21:55:35.919: E/AndroidRuntime(1415): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord#405296f0 is not valid; is your activity running?
I found a solution that I should use "getParent()" instead of "getApplicationContext()"or"this" in my code, but I don't know where/how to do it? I don't know how to do something like "setContext(getParent())" with my PreferenceActivity.
I have a problem exactly same as this: TabActivity with ActivityGroup and PreferenceActivity child
Here is my code:
public class MoreUserProfile extends PreferenceActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.more_userprofile);
}
In my opinion, I think I should implement something in a dialog class, in onCreateDialogView() because android calls this method at making dialog time. I try my best but I can't solve my problem
public class MoreUserProfileDateOfBirthDialog extends DialogPreference {
LinearLayout layout;
SharedPreferences.Editor editor;
public MoreUserProfileDateOfBirthDialog(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
setDialogLayoutResource(R.layout.more_userprofile_dialog_dateofbirth);
}
#Override
protected View onCreateDialogView() {
// TODO Auto-generated method stub
// I think I should implement some code here.
//Activity parent = new Activity();
//LayoutInflater inflater = (LayoutInflater) parent.getLayoutInflater();
//layout = (LinearLayout) inflater.inflate(R.layout.more_userprofile_dialog_dateofbirth, null);
}
protected void onBindDialogView(View view) {
layout = (LinearLayout) view.findViewById(R.id.more_userprofile_dialog_dateofbirth_linearlayout);
SharedPreferences pref = getSharedPreferences();
int day = pref.getInt("dayOfBirthday", 1);
int month = pref.getInt("monthOfBirthday", 1);
int year = pref.getInt("yearOfBirthday", 2000);
DatePicker dp = (DatePicker) view.findViewById(R.id.more_userprofile_dialog_choosedateofbirth_datePicker);
dp.init(year, month-1, day, onDateChangedListener);
layout.removeAllViews();
layout.addView(dp);
super.onBindDialogView(view);
}
DatePicker.OnDateChangedListener onDateChangedListener = new OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
editor = getEditor();
editor.putInt("dayOfBirthday", view.getDayOfMonth());
editor.putInt("monthOfBirthday", view.getMonth()+1);
editor.putInt("yearOfBirthday", view.getYear());
}
};
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
super.onClick(dialog, which);
if(which==DialogInterface.BUTTON_NEGATIVE){
dialog.dismiss();
}
if(which==DialogInterface.BUTTON_POSITIVE){
editor.commit();
}
}
}
Second question, Similar as Above, but this time is about TabActivity with ListView Adapter (Use for Custom Listview). On each Custom Listview item has 2 buttons, "Edit" and "Delete". When I click on one of these button, dialog appears. But after I apply TabActivity to my application, I got an error when press these button. The error code is similar as above:
08-10 22:13:56.643: E/AndroidRuntime(1427): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord#40526c50 is not valid; is your activity running?
Here is my code:
public class ActivityListviewAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private Context context;
private ArrayList<Activities> listData = new ArrayList<Activities>();
public ActivityListviewAdapter(Context context,ArrayList<Activities> listData,) {
// TODO Auto-generated constructor stub
super();
this.context = context;
this.mInflater = LayoutInflater.from(context);
this.listData = listData;
}
public int getCount() {
// TODO Auto-generated method stub
return listData.size(); //ส่งขนาดของ List ที่เก็บข้อมุลอยู่
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ActivityRowList activitylist;
if(convertView == null){
convertView = mInflater.inflate(R.layout.more_customizedactivity_customlistview, null);
activitylist = new ActivityRowList();
activitylist.ActivityName = (TextView) convertView.findViewById(R.id.TextView_More_Customizedactivity_Customlistview_ActivityName);
activitylist.ActivityDetail = (TextView) convertView.findViewById(R.id.TextView_More_Customizedactivity_Customlistview_ActivityDetail);
activitylist.ActivityType = (ImageView) convertView.findViewById(R.id.ImageView_Activity_ShowallActivity_Customlistview);
activitylist.EditCustomizedButton = (Button) convertView.findViewById(R.id.Button_More_Customizedactivity_Customlistview_Edit);
activitylist.DeleteCustomizedButton =(Button)convertView.findViewById(R.id.Button_More_Customizedactivity_Customlistview_Delete);
convertView.setTag(activitylist);
}else{
activitylist = (ActivityRowList) convertView.getTag();
}
activitylist.ActivityName.setText(listData.get(position).getActivityName());
activitylist.ActivityDetail.setText("MET: "+listData.get(position).getActivityMET().toString());
activitylist.ActivityType.setImageResource(R.drawable.activity_type_customized);
activitylist.EditCustomizedButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
editNewActivityDialog(listData.get(position).getActivityName(), listData.get(position).getActivityMET(),position);
}
});
activitylist.DeleteCustomizedButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
confirmDeleteCustomizedDialog(listData.get(position).getActivityName(),listData.get(position));
}
});
return convertView;
}
private void confirmDeleteCustomizedDialog(final String ActivityNameInput,final Activities listDataposition){
// TODO Auto-generated method stub
AlertDialog alertDialog = new AlertDialog.Builder(mInflater.getContext()).create();
alertDialog.setTitle("Confirm Delete");
alertDialog.setMessage("Do you want to delete:\"" + ActivityNameInput +"\"" );
alertDialog.setIcon(R.drawable.ic_launcher);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,"Confirm", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Some codes here
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,"Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
alertDialog.show();
}
private void editNewActivityDialog(final String ActivityNameBefore, float ActivityMETBefore,final int ListPosition) {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(mInflater.getContext());
dialog.setContentView(R.layout.more_customizedactivity_dialog_addnew);
final EditText EditText_Addnewactivity_Dialog_ActivityName=(EditText)dialog.findViewById(R.id.EditText_More_Customizedactivity_Addnewactivity_Dialog_ActivityName);
final EditText EditText_Addnewactivity_Dialog_ActivityMET=(EditText)dialog.findViewById(R.id.EditText_More_Customizedactivity_Addnewactivity_Dialog_ActivityMET);
final Button Button_More_Customizedactivity_Addnewactivity_Dialog_OK=(Button)dialog.findViewById(R.id.Button_More_Customizedactivity_Addnewactivity_Dialog_OK);
final Button Button_More_Customizedactivity_Addnewactivity_Dialog_Cancel=(Button)dialog.findViewById(R.id.Button_More_Customizedactivity_Addnewactivity_Dialog_Cancel);
dialog.setTitle("Edit Activity by User");
EditText_Addnewactivity_Dialog_ActivityName.setText(ActivityNameBefore);
EditText_Addnewactivity_Dialog_ActivityMET.setText(ActivityMETBefore+"");
dialog.show();
Button_More_Customizedactivity_Addnewactivity_Dialog_OK.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
// Some codes here
});
Button_More_Customizedactivity_Addnewactivity_Dialog_Cancel.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
}
}
According to my code:
When I press "Edit" on my custom listview, code runs editNewActivityDialog() method and builds Dialog by using this:
final Dialog dialog = new Dialog(mInflater.getContext());
(I think I should change "mInflater.getContext()" to something else but I don't know.)
When I press "Delete" button on my custom listview, code runs confirmDeleteCustomizedDialog() method and builds AlertDialog by using this:
AlertDialog alertDialog = new AlertDialog.Builder(mInflater.getContext()).create();
(I think I should change "mInflater.getContext()" to something else but I don't know.)
Very thanks in advance :)

get data from customize listview

Here is my code,
public class SecondScreenActivity extends Activity {
ListView foodJntListView;
ArrayList<Restaurent> restaurentData;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.second_screen);
restaurentData = getFoodJnt();
foodJntListView=(ListView)findViewById(R.id.listView_foodjnt);
foodJntListView.bringToFront();
// setting the adapter to the list
foodJntListView.setAdapter(new RestaurantBaseAdapter(this,restaurentData));
//setting the onclick listener,activity on clicking on an item of the
foodJntListView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
String hotelname=restaurentData.get(position).toString();
//things to write
}
});
}
// get all the list of foodjoints
private ArrayList<Restaurent> getFoodJnt() {
// TODO Auto-generated method stub
ArrayList<Restaurent> results=new ArrayList<Restaurent>();
Restaurent restrnt=new Restaurent();
restrnt.setFoodJointname("Ashila");
restrnt.setCuisine("Biriyani,Moughlai");
restrnt.setAddress("Kolkata,E M Bypass");
restrnt.setOpenhours("10:00am-10:00pm");
results.add(restrnt);
restrnt=new Restaurent();
restrnt.setFoodJointname("Bhajohori Manna");
restrnt.setCuisine("Bengali,Chinese");
restrnt.setAddress("Kolkata,Esplanede");
restrnt.setOpenhours("10:00am-10:00pm");
results.add(restrnt);
restrnt=new Restaurent();
restrnt.setFoodJointname("Bar B Q");
restrnt.setCuisine("Bengali,Chinese,Thai");
restrnt.setAddress("Kolkata,Park Street");
restrnt.setOpenhours("10:00am-10:00pm");
results.add(restrnt);
return results;
}
public void makeAToast(String str) {
//yet to implement
Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
I can able to show a customized listview with a bunch of textview on it as it's item but,I want to get the Name of the restauirants setOnItemClick on the List view.
e.g whenever I click Click on "Bar B Q","calcutta Food Court",it'll show me only "Bar B Q","calcutta Food Court" not other informations.
thnx in advance.Feel free to if u need anything.
"my application screen shot"
assume you've got method like getFoodJointname() in your Restaurent class, you can write the below in your onItemClick():
String hotelname = restaurentData.get(position).getFoodJointname();
makeAToast(hotelname);
this will work hopefully.
Restaurent rest= (Restaurent) foodJntListView.getSelectedItem();

Categories

Resources