I have a TreeMap with a ListView, I want the second activity to take the selected item of the ListView and use it as the Title of the second activity.
(Using Strings or Arrays instead of TreeMap I can make it work, but then the TextWatcher won't work, and using TreeMap the TextWatcher works fine).
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ListView resultsListView = (ListView) findViewById(R.id.listView);
EditText buscar = (EditText) findViewById(R.id.busqueda);
TreeMap<String, String> nameAddresses = new TreeMap<>();
nameAddresses.put ( "Coso", "Desear " );
nameAddresses.put ( "бажа́ти", "Desear " );
nameAddresses.put ( "бала́кати", "Charlar " );
final List<HashMap<String, String>> listItems = new ArrayList<>();
final SimpleAdapter adapter = new SimpleAdapter(this, listItems, R.layout.list_item,
new String[]{"First Line", "Second Line"},
new int[]{R.id.text1, R.id.text2});
Iterator it = nameAddresses.entrySet().iterator();
while (it.hasNext())
{
HashMap<String, String> resultsMap = new HashMap<>();
Map.Entry pair = (Map.Entry)it.next();
resultsMap.put("First Line", pair.getKey().toString());
resultsMap.put("Second Line", pair.getValue().toString());
listItems.add(resultsMap);
}
resultsListView.setAdapter(adapter);
resultsListView.setFastScrollEnabled(true);
resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("Want to Pass", resultsListView.getItemAtPosition(position).toString());
startActivity(intent);
}
});
}
This is the main activity, and now the second:
public class SecondActivity extends AppCompatActivity {
Toolbar mToolbar;
TextView mTextView;
TextView mTextView2;
ImageButton button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
//changing statusbar color
if (android.os.Build.VERSION.SDK_INT >= 21) {
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(this.getResources().getColor(R.color.colorPrimaryDark));
}
mToolbar = (Toolbar) findViewById(R.id.toolbar2);
mTextView = (TextView) findViewById(R.id.textView2);
mTextView2 = (TextView) findViewById(R.id.textView3);
button = (ImageButton) findViewById (R.id.imageButton);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
mToolbar.setTitle(bundle.getString("Want to Pass"));
if (mToolbar.getTitle().toString().equalsIgnoreCase("Coso")) { писа́ти
mToolbar.setSubtitle("Escribir");
The ListView shows two elements in each item ("Coso and Desear" for example) and I want either of these two to be used as Title in the toolBar of the second activity........
Related
I'm trying to display different texts for a textview according to the listview listitem click. For now Am creating Lot of new activities to achieve this task. Following Codes are one of that scenario. Is there any simple way to show the different texts in a Same Activity(BSC Activity). I dont want to create Post Activity. For an example If listview position == 0 item clicked
R.String.Bsc
have to display in bsc Activity. If position == 1 clicked
R.String.Post
Have to display in bsc activity.
ListView class
public class AHSMLS extends AppCompatActivity{
ListView list;
String[] itemname ={
"Degree in Physiotherapy",
"Post Graduate options"
};
Integer[] imgid={
R.drawable.mlsico,
R.drawable.mls
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cp_listview_main_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Physiotherapy");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ImageView img = (ImageView)findViewById(R.id.thumbnail);
img.setImageResource(R.drawable.physiotherapy);
CustomListAdapter adapter=new CustomListAdapter(this, itemname, imgid);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
if (position == 0) {
Intent intent = new Intent(getApplicationContext(), Bsc.class);
startActivity(intent);
}else if (position == 1){
Intent intent = new Intent(getApplicationContext(), Post.class);
startActivity(intent);
}
}
});
}
}
Bsc activity
public class Bsc extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multiple_text_view);
TextView tv3 = (TextView)findViewById(R.id.durationtextView);
tv3.setText("•\t 3 or 4 Year");
TextView tv4 = (TextView)findViewById(R.id.institutiontextView);
tv4.setText(R.string.bsc);
}
}
Post activity
public class Post extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multiple_text_view);
TextView tv3 = (TextView)findViewById(R.id.durationtextView);
tv3.setText("•\t 3 or 4 Year");
TextView tv4 = (TextView)findViewById(R.id.institutiontextView);
tv4.setText(R.string.Post);
}
}
If i got your question correctly. Is this one You looking For? With this solution you dont need your post class. You can change your texts with the Bsc class.
ListView class
public class AHSMLS extends AppCompatActivity{
ListView list;
String[] itemname ={
"Degree in Physiotherapy",
"Post Graduate options"
};
Integer[] imgid={
R.drawable.mlsico,
R.drawable.mls
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cp_listview_main_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Physiotherapy");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ImageView img = (ImageView)findViewById(R.id.thumbnail);
img.setImageResource(R.drawable.physiotherapy);
CustomListAdapter adapter=new CustomListAdapter(this, itemname, imgid);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Intent intent = new Intent(getApplicationContext(), Bsc.class);
Bundle bundle = new Bundle();
//Add your data to bundle
bundle.putInt("x", position);
//Add the bundle to the intent
intent.putExtras(bundle);
startActivity(intent);
}
}
});
}
}
Bsc activity
public class Bsc extends AppCompatActivity {
TextView tv3;
TextView tv4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multiple_text_view);
tv3 = (TextView)findViewById(R.id.durationtextView);
tv4 = (TextView)findViewById(R.id.institutiontextView);
//Get the bundle
Bundle bundle = getIntent().getExtras();
//Extract the data…
int stuff = bundle.getInt("x");
if(stuff == 0){
tv3.setText("•\t 3 or 4 Year");
tv4.setText(R.string.bsc);
}else if(stuff == 1){
tv3.setText("•\t 3 or 4 Year");
tv4.setText(R.string.Post);
}
}
}
So you dont need Your Post activity Here. Good luck Bro!
(sorry about the crappy formatting... still have never figured out how to preserve indentation when pasting code)
Anyhoo.... I think this is what Reaz Murshed is try to say:
public class AHSMLS extends AppCompatActivity{
// START NEW CODE
TextView tv3;
TextView tv4;
// END NEW CODE
ListView list;
String[] itemname ={
"Degree in Physiotherapy",
"Post Graduate options"
};
Integer[] imgid={
R.drawable.mlsico,
R.drawable.mls
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cp_listview_main_activity);
// START NEW CODE
tv3 = (TextView)findViewById(R.id.durationtextView);
tv3.setText("•\t 3 or 4 Year");
tv4 = (TextView)findViewById(R.id.institutiontextView);
// END NEW CODE
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Physiotherapy");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ImageView img = (ImageView)findViewById(R.id.thumbnail);
img.setImageResource(R.drawable.physiotherapy);
CustomListAdapter adapter=new CustomListAdapter(this, itemname, imgid);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
if (position == 0) {
// START NEW CODE
tv4.setText(R.string.bsc);
}else if (position == 1){
tv4.setText(R.string.Post);
// END NEW CODE
}
}
});
}
}
I am working on a program and I would like to display a ListView with 2 lines (a Heading and a text) but the lines come from 2 different string[]
how can I do that ? Here is my code right now (I only have one line)
public class MainActivity : Activity
{
Button addATaskButton;
ListView listeView;
View view;
Activity context;
private List<string> titres = new List<string>();
private List<string> textes = new List<string>();
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
addATaskButton = FindViewById<Button>(Resource.Id.AddATaskButton);
listeView = FindViewById<ListView>(Resource.Id.listeTasks);
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);
ISet<string> listeTitresTaches = new HashSet<string>(prefs.GetStringSet("Titres", new HashSet<string>()));
ISet<string> listeTextesTaches = new HashSet<string>(prefs.GetStringSet("Textes", new HashSet<string>()));
foreach (string items in listeTitresTaches)
{
titres.Add(items);
}
foreach (string items2 in listeTextesTaches)
{
textes.Add(items2);
}
//view = context.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItem2, null);
var ListAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem2, titres.ToArray());
listeView.Adapter = ListAdapter;
addATaskButton.Click += delegate
{
StartActivity(typeof(AddTaskActivity));
};
}
}
Thank you for your help !
I would like to display a ListView with 2 lines
SimpleAdapter should be suitable for you.
Try the following code:
public class MainActivity : Activity
{
ListView lv;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView (Resource.Layout.Main);
lv = FindViewById<ListView>(Resource.Id.listView1);
SimpleAdapter adapter = new SimpleAdapter(this, getData(),Resource.Layout.ListViewItem,
new string[] { "textView1", "textView2" },
new int[] { Resource.Id.textView1, Resource.Id.textView2});
lv.Adapter = adapter;
}
public List<IDictionary<string, object>> getData()
{
List<IDictionary<string, object>> list = new List<IDictionary<string, object>>();
for (int i = 0; i < 10; i++)
{
var item1 = new JavaDictionary<string, object>();
item1.Add("textView1", "Title Mike Ma");
item1.Add("textView2", "Body Mike Ma");
list.Add(item1);
}
return list;
}
}
screen shot:
I'm trying to display the name of the Listview item on the action bar as it's title on the next activity screen using intents.
Here is my code.
MathematicsDBEntry.java
public class MathematicsDBEntry extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent i = getIntent();
String newActionBarTitle = i.getStringExtra("Position");
super.onCreate(savedInstanceState);
assert getSupportActionBar() != null;
getSupportActionBar().setTitle(newActionBarTitle);
setContentView(R.layout.activity_mathematics_dbentry);
}
}
MathsActivity.java
public class MathsActivity extends ListActivity implements AdapterView.OnItemClickListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maths);
// storing string resources into Array
String[] math_data = getResources().getStringArray(R.array.maths_list_data);
ListView listView = getListView();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, math_data);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView textView = (TextView) view;
//Toast.makeText(this, textView.getText().toString() + " " + position, Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), MathematicsDBEntry.class);
intent.putExtra("Position", textView.toString());
startActivity(intent);
}
}
But all I get is the garbage value shown below.
You need to use the getText() method of TextView to get the data from it.
You need to change:
intent.putExtra("Position", textView.toString());
to:
intent.putExtra("Position", textView.getText().toString());
Hey I have tried to make a ListActivity that show the internal saved data, there have been saved from another activity. And when I click on an item, it should open a new activity with the internal data, and then open the data.
Here is the first activity. there shall show the listview and when clicked on an item, the user should be send to second activity whith more details
public class ShowListActivity extends ListActivity {
private ArrayAdapter<String> list;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_data);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setSelector(android.R.color.holo_blue_bright);
String[] filenames = getApplicationContext().fileList();
List<String> list = new ArrayList<String>();
for(int i = 0; i<filenames.length; i++){
//Log.d("Filename", filenames[i]);
list.add(filenames[i]);
}
setListAdapter(new ArrayAdapter(this,
android.R.layout.simple_list_item_1, list));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String product = ((TextView)v).getText().toString();
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("product", product);
startActivity(i);
}
Here is the other activity there shall recived the data and open it.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
TextView showCloseRange = (TextView) findViewById(R.id.show_close_range);
TextView showToRight = (TextView) findViewById(R.id.show_to_right);
TextView showToCenterRight = (TextView) findViewById(R.id.show_to_center_right);
TextView showToCenter = (TextView) findViewById(R.id.show_to_center);
TextView showToCenterLeft = (TextView) findViewById(R.id.show_to_center_left);
TextView showToLeft = (TextView) findViewById(R.id.Show_to_left);
TextView showFT = (TextView) findViewById(R.id.show_ft);
TextView showTreRight = (TextView) findViewById(R.id.show_tre_right);
TextView showTreCenterRight = (TextView) findViewById(R.id.show_tre_center_right);
TextView showTreCenter = (TextView) findViewById(R.id.show_tre_center);
TextView showTreCenterLeft = (TextView) findViewById(R.id.show_tre_center_left);
TextView showTreLeft = (TextView) findViewById(R.id.show_tre_left);
TextView showAssist = (TextView) findViewById(R.id.show_assist);
TextView showSteals = (TextView) findViewById(R.id.show_steals);
TextView showFouls= (TextView) findViewById(R.id.show_fouls);
TextView showTotalPt = (TextView) findViewById(R.id.show_total_pt);
TextView showDataBlocks = (TextView) findViewById(R.id.show_data_blocks);
TextView showDataRebounds = (TextView) findViewById(R.id.show_data_rebounds);
TextView showDataTurnOcers = (TextView) findViewById(R.id.show_data_turn_overs);
TextView showDataPlayerTime = (TextView) findViewById(R.id.show_data_player_time);
TextView showNote = (TextView) findViewById(R.id.show_note);
String value = "";
FileInputStream fis;
Intent i = getIntent();
String product = i.getStringExtra("product");
ActionBar actionBar1 = getActionBar();
actionBar1.setTitle(product);
try {
fis = openFileInput(product);
byte[] input = new byte[fis.available()];
while(fis.read(input) != -1){
value += new String(input);
fis.close(); }
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String[] strArray = value.split(";");
showCloseRange.setText(strArray[0]);
showToRight.setText(strArray[1]);
showToCenterRight.setText(strArray[2]);
showToCenter.setText(strArray[3]);
showToCenterLeft.setText(strArray[4]);
showToLeft.setText(strArray[5]);
showFT.setText(strArray[6]);
showTreRight.setText(strArray[7]);
showTreCenterRight.setText(strArray[8]);
showTreCenter.setText(strArray[9]);
showTreCenterLeft.setText(strArray[10]);
showTreLeft.setText(strArray[11]);
showDataPlayerTime.setText(strArray[12]);
showTotalPt.setText(strArray[13]);
showAssist.setText(strArray[14]);
showSteals.setText(strArray[15]);
showDataBlocks.setText(strArray[16]);
showDataRebounds.setText(strArray[17]);
showDataTurnOcers.setText(strArray[18]);
showFouls.setText(strArray[19]);
showNote.setText(strArray[20]);
}
I have trouble with sending the data between the activies and open it, so it will split up in my many differents textviews.
Any ideas ?
And sorry for my bad English
Try this way,hope this will help you to solve your problem.
Instead of geting product from ListView item TextView just declare your ArrayList object outside oncreate() and try to get your particular product using position from list in ListView item click listener.
public class ShowListActivity extends ListActivity {
private List<String> list = new ArrayList<String>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_data);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setSelector(android.R.color.holo_blue_bright);
list = Arrays.asList(getApplicationContext().fileList());
setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, list));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, MainActivity.class);
i.putExtra("product", list.get(position));
startActivity(i);
}
}
You can check what you are sending to second activity, mean using System.out.println() you can check on logcat . Also i done small change in your code please try this.
private ArrayAdapter<String> list;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_data);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setSelector(android.R.color.holo_blue_bright);
String[] filenames = getApplicationContext().fileList();
ArrayList<String> arrlist = new ArrayList<String>();
for(int i = 0; i<filenames.length; i++){
//Log.d("Filename", filenames[i]);
arrlist.add(filenames[i]);
}
setListAdapter(new ArrayAdapter(this,
android.R.layout.simple_list_item_1, arrlist ));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String product = arrlist.get(position);
//Here you can check what yo are sending to second activity using System.out.println
System.out.println("click product is : "+product);
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("product", product);
startActivity(i);
finish();
}
Ans also in other activity mean second activity you can add System.out.println to check list item value is coming or not.
String product = getIntent().getStringExtra("product");
System.out.println("product in second activity : "+product);
I am trying to send row item from list view to another activity but maybe I do something wrong.
I made one app for food.
And I want when the user click to "First Activity" the list item from this listview to be send to "Second Activity" and when the user click to "Add to cart" the listview item go to Cart.class
But when I click to "Add to cart" the Activity is send me tо Cart.class but there have nothing.
In cart.xml I have listvew.
Sorry for my bad english
Thanks in advance.
First Activity.
public class UnderCal extends Activity {
String classes[] = {"Grilled chicken","Asiago","Spicy"};
int[] meal = new int[]{
R.drawable.grilledchicken,
R.drawable.asiago,
R.drawable.spicy
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.under_menu);
final List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<3;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("food", Integer.toString(meal[i]));
hm.put("txt", "" + classes[i]);
aList.add(hm);
}
// Keys used in Hashmap
String[] from = {"food","arrow","txt"};
// Ids of views in listview_layout
int[] to = { R.id.food,R.id.arrow,R.id.txt};
// Instantiating an adapter to store each items
// R.layout.listview_layout defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.list_layout, from, to);
// Getting a reference to listview of main.xml layout file
final ListView listView = ( ListView ) findViewById(R.id.mylist);
// Setting the adapter to the listView
listView.setAdapter(adapter);
listView.setDivider(new ColorDrawable(0xffffffff));
listView.setDividerHeight(1);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
if (position == 0)
{
Intent intent = new Intent(UnderCal.this,GrilledChicken.class);
// intent.putExtra("get", aList.get(position));
String result = (String) listView.getItemAtPosition(position).toString();
intent.putExtra("get",result);
startActivity(intent);
overridePendingTransition(R.anim.animation3, R.anim.animation4);
}
}
});
}
Second Activity.
public class GrilledChicken extends Activity {
Button butadd;
//HashMap<String, String> hm;
String list;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.grilled_chicken);
//hash
// hm =(HashMap<String, String>)getIntent().getSerializableExtra("get");
Bundle extras = getIntent().getExtras();
list = extras.getString("get");
butadd=(Button) findViewById(R.id.butadd);
butadd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(GrilledChicken.this,Cart.class);
// intent.putExtra("hm",hm);
intent.putExtra("list",list);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}
});
Cart.class
public class Cart extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.cart);
Bundle extras = getIntent().getExtras();
String pos = extras.getInt("list");
}
}
For get item from your listview you have to write following code.
String item = food.get(position).toString();
Write this on your Itemclick method
Put the following code in your Cart.class
Bundle extras = getIntent().getExtras();
String list_data = extras.getString("list");
Now list_data contains the data.
There is another way through which you can do the task also.
Create a separate Global Class
Global.class
public class Globalclass {
public static String list_data;
}
And then in your FirstActivity replace the following
intent.putExtra("get",result);
with
Globalclass.list_data=result;
Now you can access the list_dataanywhere like the following
String data=Globalclass.list_data;
Try this once I hope this will help you.
First of all do this in YourFirstActivity
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity(), YourSecondActivity.class);
YourModel yourModel = (YourModel) parent.getItemAtPosition(position);
intent.putExtra("yourModel", yourModel);
startActivity(intent);
}
});
At another Activity do this.
YourModel yourModel= (YourModel) getIntent().getSerializableExtra("yourModel");
From yourModel object you will get all the data of your ListView selected item of YourFirstActivity to YourSecondActivity.
Multiple Send ListView Item:-
ArrayList<String>checked11 = new ArrayList<String>();
SparseBooleanArray checked = listView1.getCheckedItemPositions();
final ArrayList<String> selectedItems = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
int position = checked.keyAt(i);
if (checked.get(i))
selectedItems.add(checked11.get(position));
}
String[] outputStrArr = new String[selectedItems.size()];
for (int i = 0; i < selectedItems.size(); i++) {
outputStrArr[i] = selectedItems.get(i);
}
use Bunddle :
Bundle bundle = new Bundle();
Intent intent = new Intent(getApplicationContext(),
OtherActivity.class);
bundle.putStringArray("selectedItems", outputStrArr);
intent.putExtra("screen2", "sub");
intent.putExtras(bundle);
intent.putExtra(EXTRA_RESPONSE, selected);
startActivity(intent);