I don't know how to save the data from these editText(as shown below in the image) and save those data on external storage, and then fetch those data from the saved file to the respective editText boxes, the buttons which I have implemented are for Picking the contact details like name and number from phonebook, which is working properly and there are two more buttons I have included for save and load operation.
Screenshot
If I am not wrong all your controls are there, in ListView or Recyclerview.
Make sure you set tag to each of your EditText properly since based on these tags you can fetch all details from the respected EditText present on each rows.
Here is the how you can set tag to controls
#Override
public View getView(int position, View convertView, ViewGroup parent) {
rowView.setTag(yourdata_object);
return rowView;
}
You can get tag details as mentioned below
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long
id) {
YourDataObject item = (YourDataObject ) view.getTag();
Intent i = new Intent(GetRota.this, someOtherActivity.class);
i.putsomedata;
startActivity(i);
}
Related
Hello every one i have a listview of array data of checkboxes which the user will select as the hobbies below is preview
and the hobbies will be shown upside but i am stuck of removing the hobbies by clicking it on up side and also when i select the 2 hobies then in show list it shows 2 times
bellow is the preview
also if i select the 3rd hobby then it show 3 times so please fix this for me and also if i uncheck the box it should remove from the view list also if i click on any hobby in the show list it still remove and uncheck automatically and if i click on save button all the hobbies should be selected
please fix this for me bellow is my code
Hobbies_Hobbies_List.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (!Hobbies_Hobbies_List.isItemChecked(i))
{
Hobbies_Hobbies_List.setItemChecked(i,false);
}
else
{
Object object = Hobbies_Hobbies_List.getItemAtPosition(i);
String Hobby = String.valueOf(object);
for (int j=0;j<Hobbies_Hobbies_List.getCount();j++)
{
if (Hobbies_Hobbies_List.isItemChecked(j))
{
TextView text = new TextView(HobbiesActivity.this);
text.setText(Hobby+" ");
text.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
Hobbies_Show.addView(text);
}
}
}
}
});
hobbies_save_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
It seems you don't have an adapter.
In an adapter you can modify your list (add or remove item, change text, color etc)
If you want to make your own list you will have to make your own adapter for your list. You can remove items in the adapter.
public View getView(final int position, View view, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View rowView = inflater.inflate(resource, parent, false);
TextView textView = rowView.findViewById(R.id.textView);
CheckBox checkBox = rowView.findViewById(R.id.checkBox);
textView.setText(dataSet.get(position).myText);
checkBox.setChecked(dataSet.get(position).myBool);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
// You can remove item here
}
});
return rowView;
}
For this you need your own data type.
Here a project with an example:
https://github.com/Asuki/SimpleListView
You also have to add the remove items to the other one list (maybe from the adapter)
I am newbie in Android Development and i am developing a android app using recycler view and card view.I created two column using grid layout with 10 rows 20 images Now i want to set a click Listener on every image which starts a new activity that should play a giff animation or video link with that specific image.
public AlphabetRecyclerViewItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Get LayoutInflater object.
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
// Inflate the RecyclerView item layout xml
View alphabetItemView = layoutInflater.inflate(R.layout.activity_card_view_item,parent,false);
final TextView alphabetTitleView = (TextView)alphabetItemView.findViewById(R.id.card_view_image_title);
// Get alphabet image view object.
final ImageView alphabetImageView = (ImageView)alphabetItemView.findViewById(R.id.card_view_image);
alphabetImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Get Alphabet title Text
String alphabetTitle = alphabetTitleView.getText().toString();
// Create a snackbar and show it.
Snackbar snackbar = Snackbar.make(alphabetImageView,"You Clicked" + alphabetTitle + "image",Snackbar.LENGTH_LONG);
snackbar.show();
}
});
// Create and return our custom Alphabet Recycler View Item Holder object.
AlphabetRecyclerViewItemHolder ret =new AlphabetRecyclerViewItemHolder(alphabetItemView);
return ret;
}
I want to play different videos on every image user click.
Add your all images and video in arraylist and set arraylist in recycler view
after setting the adapter use the recyclerview item click and pass the video link from that position to next screen which you want to play in your video player.
For example I have Custom Adapter List View, and my list item is a layout that contains different elements: textview, imageView and so on. How can I set the color of imageview of selected list item? Suppose I want to add this item in favourite and I want to change the color of star favourite for yellow color. Thank you)
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getActivity(), PlaceName[position] + " in favourite",
Toast.LENGTH_SHORT).show();
//Do smth here, set the color of element on item, add to favourite and something else
return true;
}
});
Well, you have this line:
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
https://developer.android.com/reference/android/widget/AdapterView.OnItemLongClickListener.html
According to the docs, view is the layout that you actually clicked, so you can get the child of that View using something like this:
ImageView favorite = view.findViewById(R.id.yourFavoriteImageView);
Note that if you scroll through your list, the layout might render again, and your change won't be visible again.
view.setBackgroundColor(Color.parseColor("#222222"));
I'm creating a custom adapter and using the getView method in attempt to display a default text only ONCE. Now I'm having a problem such that when I click the first Item in the list, the default text is kept but that doesn't hold for any other items? Any suggestions?
Thanks! (My code is a bit messy as I was just trying to debug)
boolean firstTime = true;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (firstTime) {
firstTime = false;
TextView firstView = new TextView(ForgotPasswordActivity.this);
firstView.setText("Please select School");
return firstView;
}
TextView view = new TextView(ForgotPasswordActivity.this);
view.setText("Hello");
return view;
}
You must play with the getCount function :
#Override
public int getCount() {
return super.getCount() -1; // This makes the trick;
}
this trick will not show last item that you've added inside your spinner(so when you finish adding your text inside the spinner, add the text that will not be shown in the spinner, and by that it will be show as a default value before clicking the spinner).
Good luck
I'm not exactly sure what your trying to do but you could force the top row to always show the select message by checking if the position is 0. Also notice in the code below that I'm reusing the convertView if it is not null. It's faster to reuse the convertView if it is available than to recreate a new view every time.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = new TextView(ForgotPasswordActivity.this);
}
if(position == 0) {
convertView.setText("Please select School");
} else {
convertView.setText("Hello");
}
return convertView;
}
Also remember that by forcing position zero to show the select message you are not showing the actual data in the adapter at position 0. Make sure this is what you want to do or insert a dummy piece of data in the first position of the backing data array.
So, I have an ArrayList that has name and id
Gil 232
Asty 2423 and so on.
To use it in the spinner, what I did was to create two separate String Arraylists. One containing the names and the other the corresponding ids. So, that once the user is selected, I will get the corresponding id from the position.
I am not sure how to do that last part. As to, how to get the position?> parent.getItemAtPosition(pos).toString();
This gives me the name again and not the position of the name in the ArrayList which I can use to retrieve the ID from the other list. How to do it? And, is their a better way to go about it?
public class User {
public int id;
public String name;
}
public class CustomAdapter extends ArrayAdapter<Data> implements Spinner
.OnItemSelectedListener {
#Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(android.R.layout.simple_spinner_item,
parent, false);
Data data = getItem(position);
// Do something with data and view here
return view;
}
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long arg4) {
Data data = getItem(position);
// Do something with data here
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
}
Then create an ArrayList<Data> and use with your CustomAdapter.
The pos variable is the position of item selected from Spinner, so you can use this position to get the id (from second ArrayList) of corresponding name which is selected.
As a alternative you can also create a HashMap<String,String> map
and in that map put values like map.put(name,id); so when user will select value from Spinner you will have the name selected.And then use the map to get corresponding id
like String id = map.get(selected_name);
Hope it will help.