I am making an android app in which i have an activity X that displays a list and a button. Activity X calls a listview to display that list. Each list item has a number(textview) and a checkbox. I used a setonclicklistener on the checkbox, so whenever the checkbox is checked i am storing the number associated with it in a string. Now i want that whenever i click the button the msg activity should start and the numbers to be sent are the ones that are checked.
I am using the following code to start the msg activity in my X activity.
Intent msgIntent = new Intent(Intent.ACTION_VIEW, Uri
.fromParts("sms", msgnumbers, null));
msgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(msgIntent);
Now "msgsnumbers" variable is present in my listview. How do I pass it to this activity X??
I found the same question here but with no appropriate solution.
-Thanks in advance
Intent in = new Intent(Quote.this, Purchase Ysn.class);
in.putExtra("price", salesprc);
public static String price = "price";
if (getIntent().getExtras().containsKey(price)) {
purces_nbcpy = getIntent().getExtras().getDouble(price);
}
onItemClickListener for ListView has a param position that tells you what position has been clicked.
so if you are using an ArrayList (for eg) to provide values for listItems in adapter you can use this inside onItemClickListener
MyBeanObject object=arraList.get(position);
//use getters of object to retrieve values and pass it as intent
//where arrayList may be your list of objects MyBeanObject
Related
hi i have RecyclerView in that when user click on one row i am making changes in ui and updating view now i want when user click one one icon of that row it opening 2nd activity in that i am passing object of that position . and on 2nd activity if tick it i am not able to update view of that RecyclerView .. any way ? ya by doing static arreylist i can do it but cant do static as there is some problem .. part form static other way
icon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent n = new Intent(mContext, PlayerInfo.class);
Players mData = (Players) v.getTag();
((Activity) mContext).startActivityForResult(n, 1111);
}
});
As you code shows,you can start second activity by call startActivityForResult and pass your data to it.
when data changed in 2nd activity,you save the new data in one object and when the activity finishes,you pass it to first activity,and you also need to add some code to handle the new object from 2nd activity in onActivityResult,just copy data to your old data for specific position.
So I have a listview in my activity1 class, what i want to do is:
Click on an item in the listview, which will open activity2 class, with 2 edit texts with the values from the clicked item in the listview, like name and age strings, I want to edit those values/strings in my activity2 class [by changing the edit texts], and send the edited values back to my listview in activity1 class, and show the edited values in my listview [for example show the name] instead of showing the old value/string that was in the listview before the edit.
I have tried many different ways, and I couldn't accomplish the goal, I would love if any of you could help me.
Thank you,
You can transfer your selected items data to your second activity like this code below
Intent i = new Intent(MainActivity.this,ReportActivity.class);
i.putExtra("MainDate", MainDate.getText().toString());
and in your second activity you have to get this data's and then manipulate them
Intent intent = getIntent();
MainDate = intent.getExtras().getString("MainDate");
then send back your manipulated data's to your first Activity just like before then update your list adapter
you can have data of your selected item in your first activity list by this code which lies on yourList.setOnItemClickListener
Cursor Getdata = (Cursor)YourList.getItemAtPosition(position);
String Yourcolumnstring = Getdata.getString(Getdata.getColumnIndex("yourcolumnindex")) ;
you should send your strings to activity2 and when retun from activity2 to activity1 should send your new strings from activity2 to activity1.you should your strings send as following:
String str = "My Data"; //Data you want to send
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("name",str);
you should receive str in activity2 as following:
String name = this.getIntent().getStringExtra("name");
I want to display each of the element or value of arraylist to tv.setText.
The values of the arraylist are from the 1stactivity(1st screen) and I want to pass it to the tv.setText of the 2nd activity(2nd screen).
Here's the code of 1st activity
List<String> class_code = new ArrayList<String>();
class_code.add("test");
class_code.add("test2");
Intent intent = new Intent(1stscreen.this,2nd_screen.class);
intent.putStringArrayListExtra("code", (ArrayList<String>) class_code);
Here's the code of 2nd activity
tv.setText(getIntent().getExtras().getString("code"));
But it shows all the value of arraylist (test and test2) I only want to get the first value of the arraylist.
To display only one item from an ArrayList in a TextView, you need to pass only the first item:
List<String> list = getIntent().getExtras().getStringArrayListExtra("code");
tv.setText(list.get(0));
If you only plan to use this one String in the next Activity don't pass the entire ArrayList, only pass the String you want to use:
Intent intent = new Intent(1stscreen.this, 2nd_screen.class);
intent.putString("code", class_code.get(0));
if you want only one value use something like this class_code.get(0)
intent.putString("code", class_code.get(0));
and you can get it from the next activity using
getintent().getExtras().getString("code");
Use this:
List<String> list = getIntent().getStringArrayListExtra("code");
tv.setText(list.get(0));
If you only want to use the first value, then only pass the first value. Instead of
intent.putStringArrayListExtra("code", (ArrayList<String>) class_code);
try putting
intent.putStringExtra("code", class_code.get(0));
I need to forward the value from the 1st screen to the third screen so I solved it using
1st screen
intent.putStringArrayListExtra("class_code", (ArrayList<String>) class_code);
2nd screen
intent.putStringArrayListExtra("class_code", getIntent().getExtras().getStringArrayList("class_code"));
3rd screen
tv.setText(getIntent().getExtras().getStringArrayList("class_code").get(0));
I have 3 activities and 1 class;
MobilEpostaActivity (Main Activity) gives the datas from the Gmail server intent these datas to ListeleActivity (Fill and show the ListView) and ListeleActivity fills these datas to the ListView and when item onClick on ListView the item's click datas is intent to the GoruntuleActivity (Show the onclick item's information). And also I have a class "Baglantı" (means Connection) and it has all other methods which are necessary for each.
My problem is in here: when the user click on to the "Delete" button. I want to refresh the listview and show the next mail to the user. when user clicks to the delete button, I can show the user next mail with add 1 to the position and show it. But it is not work properly, because of its attachments are complicated.
Now starting with the MobilEpostaActivity; I am taking the username and password from the user and pass them to Baglantı class for connection to the server. Then I am gettin the result body, from, subject in arraylists. Then I pass these body, from and subject to the ListeleActivity with intent.
public void epostaListeleme() throws MessagingException, IOException
{
final Intent intent = new Intent(this, ListeleActivity.class);
intent.putStringArrayListExtra(bodylistesi ,(ArrayList<String>) getBodyList());
intent.putStringArrayListExtra(konulistesi ,(ArrayList<String>) getKonuList());
intent.putStringArrayListExtra(kimdenlistesi ,(ArrayList<String>) getKimdenList());
startActivity(intent);
}
In the ListeleActivity():
Getting the datas from the MobilEpostaActivity with Bundle. Filling the listview with "from" data. And waiting for listItemOnClick. If Onclick Action is happen then pass the datas to the GoruntuleActivity.**
In the GoruntuleActivity():
Getting the datas from the ListeleActivity with Bundle. And (Here is the important part) waiting for the Delete Button OnClick. If On Onclick Action is happen FIRST) delete the position from the ListView.
arrayAdapter.remove(arrayAdapter.getItem(position));
listBaglanti.RefreshedPositions(position);
arrayAdapter.notifyDataSetChanged();
SECOND) Delete the position's datas from the bodylist , fromlist and subjectlist:
public void RefreshedPositions(int position)
{
list.remove(list.get(position));
kimdenlist.remove(kimdenlist.get(position));
konulist.remove(konulist.get(position));
}
THIRD) Hold these "changed" lists in arraylists:
bodylistRefresh = baglan.list;
kimdenlisteRefresh = baglan.kimdenlist;
konulisteRefresh = baglan.konulist;
FOURTH) Set these "changed" lists to the MobilEpostaActivity's intent (the one of ListeleAcitivity's):
MobilEpostaActivity mobilObject = new MobilEpostaActivity();
mobilObject.setKonuList(konulisteRefresh);
mobilObject.setKimdenList(kimdenlisteRefresh);
mobilObject.setBodyList(bodylistRefresh);
As you think the process should start over again. But it doesn't start because with the Fourth step, I don't think so I made a refresh for the ListView.
Maybe I went a way which one is hard. But I hope, you tell me the right thing for refresh the listview and show the next mails. Also my screenshots;
When I first open the application : There is 3 mails from Merve. Positions : 0,1,2*
After Click the Delete Button : The ListView is refresh and the position=1's item is deleted. But it is not deleted on GoruntuleActivity's Screen.
It looks like you have too many lists involved. I think that you should be able to just remove the item from the main list like so:
arrayAdapter.remove(position);
listBaglanti.RefreshedPositions(position);
arrayAdapter.notifyDataSetChanged();
public void RefreshedPositions(int position)
{
list.remove(position);
kimdenlist.remove(position);
konulist.remove(position);
}
Just pass in the position as an int value instead of retrieving and then removing the object.
I am writing an Android application with a main page being a list of categories, and then beside each category there is an edit button.
When edit button is clicked, an entry form with the "category" properties filled up is supposed to be shown.
How to pass the category ID or name to the new created form so that it could load from database the properties of selected category
I have no issue with getting the selected category name, by using the code below:
public String getSelectedItem(View view) {
LinearLayout vwParentRow = (LinearLayout) view.getParent();
TextView child = (TextView) vwParentRow.getChildAt(0);
return (String) child.getText();
}
//edit button clicked
public void editCategoryHandler(View view) {
Intent i = new Intent(this, EntryCategory.class);
startActivity(i);
}
I am sure you have just passed String array or ArrayList to display inside that Category List, instead you should prepare an ArrayList of Category objects, and then whenever user clicked a particular item from a category list, get that object at that position after implementing OnItemClickListener, and then pass this received object to the desired activity.
In short, get object for a clicked item and then pass this object.
To pass the value to a new activity, you have to use putExtra() and getExtra().
Please refer the following page
How to use putExtra() and getExtra() for string data