I have a long list of number and i want to open dialer with same number which is clicked if i use
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:123"));
startActivity(intent);
then I have to write code for every number I want to know how to use single code for every number please help me
ArrayList Phone_Numbers=new ArrayList();
First of all put all the number in the arraylist
then create a listview and set that arraylist to it.
Populating a ListView using an ArrayList?
then seta setonitemclicklisterner on that list for that have a look at below link
http://androidexample.com/Create_A_Simple_Listview_-_Android_Example/index.php?view=article_discription&aid=65&aaid=90
Explanation for below code
when you will click on the item on list below listener will be invoked and on that by using int position you can get the specific Phone Number.
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// in itemValue you will have the phone number.
String itemValue = Phone_Numbers.get(position);
//now call the function to open the dialer with that specified number
open_Phone_Dialer(itemValue);
}
});
public void open_Phone_Dialer(String phone_Number) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phone_Number));
startActivity(intent);
}
Related
I've an issue with onItemclicklistener.
I'm getting real time data from firebase
What I want is, getting real time orders and when I click any specific order, it will go to another activity where specific details of that specific order should be shown.
How I get this?
Switch Statements will not work in this scenario.
How I get some id that will match in database, so that I can get that particular details.
I tried this method
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
String name=(String)adapterView.getItemAtPosition(i);
Intent i=new Intent(order.this,details.class);
i.putExtra("CATEGORY", name);
startActivity(i);
}
});
and in details class
Intent i = new Intent();
String name=i.getStringExtra("CATEGORY");
databaseReference=FirebaseDatabase.getInstance().getReference(Constans.CATEGORIES).child(name);
But it is crashing.
Assuming that the ListView contains the order names and the item on which the user click is the name of the order, to get that name of the order you need to use this code inside onItemClick() method:
String orderName = (String) adapterView.getItemAtPosition(position);
Hope it helps.
You can pass the item_id with firebase notification and store it in the listview adapter.
Later you can pass this id to the new activity by putting in extras.
I am kind of new to android studio, I have an array of strings for my list and when i click on an item from that list it takes me to the correct page. However, there are 100 items on the list and it's not logical to create 100 java files for all of them to set the text on that page.
My question is: is there a way to set the text to the correct item of list just after or before clicking that item?
Assuming you have in your FirstActivity a ListView please use the following code:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
String item = (String) adapterView.getItemAtPosition(position);
Intent intent = new Intent(YourActivity.this, SecondActivity.class);
intent.putExtra("item", item);
startActivity(intent);
}
});
To get the item in your SecondActivity please use this code:
String item = (String) getIntent().getExtras().get("item");
yourTextView.setText(item);
Hope it helps.
This question already has answers here:
How do I pass data between Activities in Android application?
(53 answers)
Closed 6 years ago.
I am making one Android Application and I am Stuck at One Point and need help for it.
I have the List Of Doctors. each list row contains only DoctorName and Speciality.
I want to show each Doctors Information Like his Address,Phone number etc.on its ItemClick in new Layout.
How to Pass this two Parameters(DocName,Speciality) through onItemClickListner() according to Position using Intent to Open my New Activity(DoctorInfo)
How to retrive that text value of DoctorName of each row which i Select using setOnItemClickListner()
how to resolve it???
this is my listner method
lstDoctorList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String DocName = view.findViewById(R.id.txtDoctorName).;// I want Solution for this Line
Intent i = new Intent(DoctorsActivity.this,DoctorInfo.class);
i.putExtra("DocName",DocName);
startActivity(i);
}
});
How I will get DoctorName to Pass my New Activity???
in your setOnItemClickListener()
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
intent.putExtra("Doctorname", DocName);
startActivity(intent);
get intent in your second activity:
Intent intent = getIntent();
String dn = intent.getStringExtra("Doctorname");
This is how you pass data from one activity to another activity :
ListView listView = getListView();
// listening to single list item on click
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// selected item
HERE YOU GOT POSITION FOR PARTICULAR ITEM
// Launching new Activity on selecting single List Item
Intent intent = new Intent(getBaseContext(), ActivityToLaunch.class);
intent.putExtra("DOCTOR_NAME", here get the doctor name from your list using the position arg);
startActivity(intent);
}
});`
And in ActivityToLaunch
Intent intent = getIntent();
String getDoctorName = intent.getStringExtra("DOCTOR_NAME");
I want retrieve the data from the Listview, where my list is having 4 items like, name, date, sem, category.
i want to read the text present in the list view and pass it to another activity.
If you are retrieving your data from server then you need to get item on item click of ListView. Like
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String name =urarraylist.get(position).get("name");// here you have to pas keyname which is put inyour Hashmap arraylist
String category =urarraylist.get(position).get("category");
String date=urarraylist.get(position).get("date");
String sem=urarraylist.get(position).get("sem");
Intent i = new Intent(getBaseContext(),anotheractivity.class);
i.putExtra("name", name);
i.putExtra("category ", category );
i.putExtra("date", date);
i.putExtra("sem", sem);
startActivity(i);
}
});
Now retrieve this data in your next Activity on onCreate() method. Like
Intent n = getIntent();
String name = n.getStringExtra("name");
String category = n.getStringExtra("category ");
String date= n.getStringExtra("date");
String sem= n.getStringExtra("sem");
As it's name suggest, a ListView doesn't contains data, it only contains Views. These views are often created from an array or a List via an Adapter. So you have to ask your adapter to retrieve the data.
Unfortunately there is no default method for that, so you'll have to create your own getter, or you can also loop on the getItem() method associated with the getCount() one on your ListView's adapter.
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String name=(String)parent.getItemAtPosition(position);
Intent i = new Intent(getBaseContext(),anotheractivity.class);
i.putExtra("USERNAME", name);
startActivity(i);
}
});
if you click the listview row the value from corresponding position will be fetched and passed to intent and further to next activity.
The magic lies here:
String name=(String)parent.getItemAtPosition(position);
Let's say i have a list of cities from a country.
If the user clicks one of them, i want a new screen to be displayed, with the detailed infos for that list element.
Also, that screen will have others buttons ( eg: Write Review, Post Picture )
How can i achieve this ?
The City class should implement Parcelable. Its toString() method should return the name of the city. (Rather than simply having the city as a String.)
When you populate your ListView, use an ArrayAdapter<City> instead of an ArrayAdapter<String> (this code assumes that the cities are kept in List<City> list):
City[] cities = new City[list.size()];
list.toArray(cities);
mListView = (ListView) findViewById(R.id.citylist);
mListView.setAdapter(new ArrayAdapter<City>(this,
R.layout.listitem, cities));
In your onItemClick handler, get the selected city and add it as an extra on the intent you use to launch your details activity:
mListView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int position, long id) {
City city = (City) a.getItemAtPosition(position);
Intent intent = new Intent(v.getContext(), DetailsActivity.class);
intent.putExtra("com.example.cities.City", city);
startActivity(intent);
}
});
In your details activity, get the city from the extras on the intent:
Bundle bundle = getIntent().getExtras();
City city = bundle.getParcelable("com.example.cities.City");