I have two activities. FirstActivity contains an onClick button which takes to SecondActivity. SecondActivity contains multiple EditText and a Save Button. After clicking save button I want to show all the data in the FirstActivity in ListView. I did it using TextView in FirstActivity but I am not able to use to ListAdapter.
public class MainActivity extends AppCompatActivity{
private ListView list_view;
List list;
private Button FloatingActionButton;
private TextView vortext;
private TextView nachtext;
private TextView strtext;
private TextView orttext;
private TextView text1;
private ArrayAdapter<String> ArrayAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vortext = (TextView) findViewById(R.id.vortext);
nachtext = (TextView) findViewById(R.id.nachtext);
strtext = (TextView) findViewById(R.id.strtext);
orttext = (TextView) findViewById(R.id.orttext);
list = new ArrayList<String>();
vortext.setText(getIntent().getStringExtra("Vorname"));
nachtext.setText(getIntent().getStringExtra("Nachname"));
strtext.setText(getIntent().getStringExtra("Strasse"));
orttext.setText(getIntent().getStringExtra("Ort"));
list_view = (ListView) findViewById(R.id.list_view);
String [] strings = new String[] {};
ArrayAdapter<HashMap<String,String>> listItem = new ArrayAdapter<HashMap<String, String>>();
HashMap<String,String>map;
map = new HashMap<String, String>();
map.put();
listItem.add(map);
ArrayAdapter = new ArrayAdapter<String>(this,R.layout.listitem,strings);
FloatingActionButton myFab = findViewById(R.id.fab);
myFab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivityForResult(new Intent(MainActivity.this, DetailActivity.class), 12);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 12) {
String vs = data.getExtras().getString("vs");
Log.d("MainActivity",vs);
String ns = data.getExtras().getString("ns");
Log.d("MainActivity",ns);
String ss = data.getExtras().getString("ss");
Log.d("MainActivity",ss);
String os = data.getExtras().getString("os");
Log.d("MainActivity",os);
}
}
}
Here this is my DetailsActivity
public class DetailActivity extends AppCompatActivity {
private EditText Vorname;
private EditText Nachname;
private EditText Strasse;
private EditText Ort;
private Button Save;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Vorname = (EditText) findViewById(R.id.Vorname);
Nachname = (EditText)findViewById(R.id.Nachname);
Strasse = (EditText)findViewById(R.id.Strasse);
Ort = (EditText) findViewById(R.id.Ort);
Save = (Button) findViewById(R.id.Save);
Save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String vs = Vorname.getText().toString();
String ns = Nachname.getText().toString();
String ss = Strasse.getText().toString();
String os = Ort.getText().toString();
Intent intent = new Intent(getBaseContext(),MainActivity.class);
intent.putExtra("vs", vs);
intent.putExtra("ns",ns);
intent.putExtra("ss",ss);
intent.putExtra("os",os);
setResult(RESULT_OK, intent);
finish();
}
});
}
}
Please run this sample, it may helps you
FirstActivity
public class FirstActivity extends AppCompatActivity {
private List<String> mCityList;
LinearLayoutManager mLinearLayoutManager;
RecyclerView mRecyclerView;
SampleDataAdapter adapter;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_activity);
mCityList=new ArrayList<String>();
mRecyclerView = (RecyclerView)findViewById(R.id.recycleView);
button = (Button)findViewById(R.id.buttonFirst);
mLinearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
adapter = new SampleDataAdapter(mCityList,this);
mRecyclerView.setAdapter(adapter);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivityForResult(intent, 1);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
{
if (resultCode == Activity.RESULT_OK) {
ArrayList<String> returnValue = data.getStringArrayListExtra("LIST");
mCityList.addAll(returnValue);
adapter.notifyDataSetChanged();
}
}
}
}
list_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/buttonFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
SecondActivity
public class SecondActivity extends AppCompatActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);
button = (Button)findViewById(R.id.buttonSecond);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ArrayList<String> list=new ArrayList<>();
list.add("A");
list.add("B");
list.add("C");
list.add("D");
list.add("E");
list.add("E");
list.add("G");
Intent intent = new Intent();
intent.putStringArrayListExtra("LIST",list);
setResult(RESULT_OK,intent);
finish();
}
});
}
}
second_Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/buttonSecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:text="Second"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
SampleDataADapter
public class SampleDataAdapter extends RecyclerView.Adapter<SampleDataAdapter.Items> {
private List<String> list;
private Context context;
public SampleDataAdapter(List<String> list, Context context) {
this.list = list;
this.context = context;
}
#Override
public SampleDataAdapter.Items onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item_text, parent, false);
return new Items(view);
}
#Override
public void onBindViewHolder(final SampleDataAdapter.Items holder, int position) {
holder.mEventName.setText(list.get(position));
}
#Override
public int getItemCount() {
return list.size();
}
public class Items extends RecyclerView.ViewHolder {
private TextView mEventName;
public Items(final View itemView) {
super(itemView);
mEventName = (TextView) itemView.findViewById(R.id.textView);
}
}
}
item_text.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/constraintLayout"
tools:context="com.example.android.broadcasereceiver.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="#android:color/black"
android:textStyle="bold"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="#+id/textView" />
</android.support.constraint.ConstraintLayout>
if you want to this with ListView just add in OnActivityResult
if (resultCode == Activity.RESULT_OK) {
ArrayList<String> returnValue = data.getStringArrayListExtra("LIST");
ArrayAdapter<String> itemsAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, returnValue);
mListView.setAdapter(itemsAdapter);
}
enter code here
and remove SampleDataAdapter related code from FirstActivity and take ListView instead of RecyclerView
I found so many issues in your code. for ex- you didn't set adapter to your list, you were using two different list. So I modified your code. Please use this code. You need to take list as Global Variable, and you need to set adapter to your list view. And when you are taking your results back from second activity then add those elements in your list and call ArrayAdapter.notifyDataSetChanged();
to get new data in your listview.
public class MainActivity extends AppCompatActivity {
private ListView list_view;
List list;
private Button FloatingActionButton;
private TextView vortext;
private TextView nachtext;
private TextView strtext;
private TextView orttext;
private TextView text1;
private android.widget.ArrayAdapter<String> ArrayAdapter;
private ArrayList<String> strings;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vortext = (TextView) findViewById(R.id.vortext);
nachtext = (TextView) findViewById(R.id.nachtext);
strtext = (TextView) findViewById(R.id.strtext);
orttext = (TextView) findViewById(R.id.orttext);
list = new ArrayList<String>();
vortext.setText(getIntent().getStringExtra("Vorname"));
nachtext.setText(getIntent().getStringExtra("Nachname"));
strtext.setText(getIntent().getStringExtra("Strasse"));
orttext.setText(getIntent().getStringExtra("Ort"));
list_view = (ListView) findViewById(R.id.list_view);
strings = new ArrayList<String>();
ArrayAdapter = new ArrayAdapter<String>(this, R.layout.listitem, strings);
list_view.setAdapter(ArrayAdapter);
com.google.android.material.floatingactionbutton.FloatingActionButton myFab = findViewById(R.id.fab);
myFab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivityForResult(new Intent(MainActivity.this, DetailActivity.class), 12);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 12) {
String vs = data.getExtras().getString("vs");
Log.d("MainActivity", vs);
strings.add(vs);
String ns = data.getExtras().getString("ns");
Log.d("MainActivity", ns);
strings.add(ns);
String ss = data.getExtras().getString("ss");
Log.d("MainActivity", ss);
strings.add(ss);
String os = data.getExtras().getString("os");
Log.d("MainActivity", os);
strings.add(os);
ArrayAdapter.notifyDataSetChanged();
}
}
}
Related
I am trying to send an ArrayList from NoteActivity to MainActivity.
ArrayList<String> data = new ArrayList<String>();
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_pad);
final FloatingActionButton button =
(FloatingActionButton)findViewById(R.id.save_button);
button.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
SaveData();
}
});
}
public void SaveData()
{
FileOutputStream outputStream;
try
{
EditText editText = findViewById(R.id.textView3);
final String str = editText.getText().toString();
String content = findViewById(R.id.textView).toString();
Log.d("Test","inside try block");
outputStream = openFileOutput(str, Context.MODE_PRIVATE);
outputStream.write(content.getBytes());
Toast.makeText(getApplicationContext(),"Note
saved",Toast.LENGTH_SHORT).show();
Log.d("Test","save done");
final String str1 = editText.getText().toString();
data.add(str1);
SendData();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void SendData()
{
EditText editText = findViewById(R.id.textView3);
Log.d("Check","str:"+data);
Intent intent = new Intent(NotePad.this,MainActivity.class);
intent.putExtra(EXTRA_MESSAGE, data);
startActivity(intent);
}
}
My Main Activity
public class MainActivity extends AppCompatActivity
{
private RecyclerView recyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager layoutManager;
ArrayList<String> notes = new ArrayList<String>();
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
notes = intent.getStringArrayListExtra(NotePad.EXTRA_MESSAGE);
Log.d("Check","title added: "+notes);
final FloatingActionButton button =
(FloatingActionButton)findViewById(R.id.add_notebutton);
button.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this,NotePad.class);
startActivity(intent);
}
});
recyclerView = (RecyclerView)findViewById(R.id.recycle_list);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
mAdapter = new MyAdapter(notes);
recyclerView.setAdapter(mAdapter);
}
}
my Adapter code
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>
{
ArrayList<String> Notes_list = new ArrayList<String>();
public MyAdapter(ArrayList<String> notes)
{
Notes_list = notes;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int
viewType)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.list_items,parent,false);
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position)
{
holder.mTextView.setText(Notes_list.get(position));
}
#Override
public int getItemCount()
{
return Notes_list.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder
{
TextView mTextView;
public MyViewHolder(#NonNull View itemView)
{
super(itemView);
mTextView = (TextView) itemView.findViewById(R.id.view_holder);
}
}
}
I dont receive any data in my notes (arrayList). When I run the code
The app instantly crashes with a null pointer exception.
Error: java.lang.NullPointerException: Attempt to invoke virtual method 'int
java.util.ArrayList.size()' on a null object reference at
com.example.quicknote.MyAdapter.getItemCount(MyAdapter.java:39)
You are trying to pass ArrayList and you read data from intent with getStringArrayListExtra method. You have to put data like this:
intent.putStringArrayListExtra(EXTRA_MESSAGE, data);
Edit: Check if intent has key:
if (intent.hasExtra(NotePad.EXTRA_MESSAGE)) {
notes = intent.getStringArrayListExtra(NotePad.EXTRA_MESSAGE);
}
Note: If this is just a playground it is OK. But if you trying to
build something then your architecture is wrong. It is not a good idea
to pass same array every time between two activity. You can use
startActivityForResult method and get new note onActivityResult method
of MainActivity.
Try this:-
Intent intent = new Intent(NotePad.this,MainActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("EXTRA_MESSAGE", data);
intent.putExtras(bundle);
//in MainActivity.class
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
ArrayList<String> data=(ArrayList<String>)bundle.getSerializable("EXTRA_MESSAGE");
The best way given in android document to send the arraylist or any custom object from one activity to another to Try the light weight process for this in android
Read the full overview about it https://developer.android.com/reference/android/os/Parcelable
hope it will help for you
I'm creating an app where there's cardviews and in every cardview there is a button "choose picture" and a imageView and some data, I want to make the user get a photo from gallery when button "choose file" is pressed and display it and display it in the same cardview of RecyclerView.
I tried this in my MainActivity :
mButtonChooseImage = findViewById(R.id.button_choose_image);
// I got an error in this line
mButtonChooseImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openFileChooser();
}
});
private void openFileChooser(){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,PICK_IMAGE_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
#Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK &&
data != null
&& data.getData() != null){
mImageUri = data.getData();
Picasso.with(this).load(mImageUri).into(mImageView);
}
}
I tried also in the RecyclerViewAdapter to do a function openFileChooser() but it doesn't work because i can not call onActivityResult in my recyclerViewAdapter.
how we can recover the result of onActivityResult inside an Adapter? I've read some about interfaces, but i couldn't be able trying implementing this.
this is my my activity_main layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"/>
</RelativeLayout>
this my example_item layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:id="#+id/image_view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="#drawable/ic_launcher_background" />
//this is my button"choose image"
<Button
android:id="#+id/button_choose_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="choose file" />
<TextView
android:id="#+id/text_view_creator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="creator name"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/text_view_ingredients"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ingredients:"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/text_view_likes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="like: "
android:textColor="#android:color/black"
android:textSize="20sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
th is my MainActivity :
public class MainActivity extends AppCompatActivity {
private RecyclerView mRecyclerView;
private ExampleAdapter mExampleAdapter;
private ArrayList<ExampleItem> mExamplelist;
private RequestQueue mRequestQueue;
private static final int PICK_IMAGE_REQUEST = 1;
private Button mButtonChooseImage;
private ImageView mImageView;
private Uri mImageUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mExamplelist= new ArrayList<>();
mRequestQueue= Volley.newRequestQueue(this);
parseJSON();
mButtonChooseImage = findViewById(R.id.button_choose_image);
//I have an error in this line
mButtonChooseImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openFileChooser();
}
});
}
//this is my openFilechooser function
private void openFileChooser(){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,PICK_IMAGE_REQUEST);
}
//this is my overrided onActivityresult function
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null
&& data.getData() != null){
mImageUri = data.getData();
Picasso.with(this).load(mImageUri).into(mImageView);
}
}
private void parseJSON(){
String url = "https://srehwald.github.io/eat-api/mensa-garching/2019/24.json";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
mExamplelist = new ArrayList<ExampleItem>();
//loop in days
JSONArray jsonArray = response.getJSONArray("days");
for (int i=0;i<jsonArray.length();i++){
JSONObject day = jsonArray.getJSONObject(i);
String dishesarray = day.getString("dishes");
String date = day.getString("date");
//loop in dishes
JSONArray JsonDishes = new JSONArray(dishesarray);
for (int j=0;j<(JsonDishes.length());j++){
JSONObject json_obj=JsonDishes.getJSONObject(j);
String namedishes=json_obj.getString("name");
Double dishes_price=json_obj.getDouble("price");
String ingredients=json_obj.getString("ingredients");
mExamplelist.add(new ExampleItem("test",namedishes,dishes_price,ingredients));
}
}
mExampleAdapter = new ExampleAdapter(MainActivity.this, mExamplelist);
mRecyclerView.setAdapter(mExampleAdapter);
} catch (JSONException e)
{
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mRequestQueue.add(request);
}
}
and this is my ReyclerViewadapter :
public class ExampleAdapter extends RecyclerView.Adapter<ExampleAdapter.ExampleViewHolder> {
private Context mContext;
private ArrayList<ExampleItem> mExampleList;
public ExampleAdapter(Context context, ArrayList<ExampleItem> exampleList){
mContext = context;
mExampleList = exampleList;
}
#NonNull
#Override
public ExampleViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.example_item, parent, false);
ExampleViewHolder evh = new ExampleViewHolder(v);
return evh;
}
#Override
public void onBindViewHolder(#NonNull ExampleViewHolder holder, int position) {
ExampleItem currentItem = mExampleList.get(position);
String imageUrl = currentItem.getmImageUrl();
String creatorName = currentItem.getMcreator();
String ingredients = currentItem.getMingredients();
Double likeCount= currentItem.getmLikes();
holder.mTextViewCreator.setText(creatorName);
holder.mTextViewLikes.setText("like: "+likeCount);
holder.mingredients.setText("Ingredients :"+ingredients);
Picasso.with(mContext).load(imageUrl).fit().centerInside().into(holder.mImageView);
}
#Override
public int getItemCount() {
return mExampleList.size();
}
public class ExampleViewHolder extends RecyclerView.ViewHolder{
public ImageView mImageView;
public TextView mTextViewCreator;
public TextView mTextViewLikes;
public TextView mingredients;
public Button mTakephoto;
public ExampleViewHolder(#NonNull View itemView) {
super(itemView);
mImageView=itemView.findViewById(R.id.image_view);
mTextViewCreator=itemView.findViewById(R.id.text_view_creator);
mTextViewLikes=itemView.findViewById(R.id.text_view_likes);
mingredients=itemView.findViewById(R.id.text_view_ingredients);
mTakephoto=itemView.findViewById(R.id.button_choose_image);
}
}
}
I expect that user can choose a picture from gallery when the button "choose picture" and would be dislpay it in the same Cardview where the button is presssed.
Thank you for your time in advance.
I write this code for search in recyclerview with edit text but, when I run the application and input a text that I need to search about it on the edit text in the first letter the recycler content not changed and when I input the second Letter the RecyclerView become empty.
how can I filter the recycler? what is the wrong in my code ?
xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FamilyActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/search"
android:layout_width="294dp"
android:layout_height="70dp"
android:layout_marginTop="-20dp"
android:hint="Search ..."
android:drawableLeft="#drawable/ic_search_black_24dp"
/>
<Button
android:id="#+id/add"
android:layout_width="54dp"
android:layout_height="match_parent"
android:layout_marginLeft="35dp"
android:drawableTop="#drawable/ic_person_add_black_24dp"
android:onClick="add_new_family"
tools:ignore="OnClick" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="50dp"></android.support.v7.widget.RecyclerView>
</RelativeLayout>
code in main activity:
public class FamilyActivity extends AppCompatActivity {
RecyclerView recyclerView;
FamilyAdapter familyAdapter;
Button add_family;
EditText search;
List<Family> familyList;
String patientID = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_family);
add_family=(Button)findViewById(R.id.add);
search =(EditText)findViewById(R.id.search);
familyList = new ArrayList<>();
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
Bundle extras = getIntent().getExtras();
if (extras != null) {
patientID = extras.getString("ID");
}
loadFamilyList();
//adding some items to our list
//creating recyclerView adapter
FamilyAdapter adapter = new FamilyAdapter(this, familyList);
//setting adapter to recyclerView
recyclerView.setAdapter(adapter);
addTextListener();
}
public void addTextListener(){
search.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence query, int start, int before, int count) {
query = query.toString().toLowerCase();
final List<Family> filteredList = new ArrayList<>();
for (int i = 0; i < familyList.size(); i++) {
final String text = familyList.get(i).toString().toLowerCase();
if (text.contains(query)) {
filteredList.add(familyList.get(i));
}
}
recyclerView.setLayoutManager(new LinearLayoutManager(FamilyActivity.this));
FamilyAdapter fadapter = new FamilyAdapter(FamilyActivity.this,filteredList);
recyclerView.setAdapter(fadapter);
fadapter.notifyDataSetChanged(); // data set changed
}
});
}
code in adapter:
public class FamilyAdapter extends RecyclerView.Adapter<FamilyAdapter.FamilyViewHolder> {
private Context context;
private List<Family> familyList;
private List<Family> familyListFull;
public FamilyAdapter(Context context, List<Family> familyList) {
this.context = context;
this.familyList = familyList;
familyListFull=new ArrayList<>(familyList);
}
#NonNull
#Override
public FamilyViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.list_layout, null);
return new FamilyViewHolder(view);
}
#Override
public void onBindViewHolder(FamilyViewHolder familyViewHolder, final int position) {
Family family = familyList.get(position);
familyViewHolder.textViewTitle.setText(family.getName());
familyViewHolder.familyLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: clicked on : " + familyList.get(position));
String name = familyList.get(position).getName();
String num = familyList.get(position).getNum();
Intent intent = new Intent(context, Chatting.class);
intent.putExtra("num", num);
intent.putExtra("name", name);
context.startActivity(intent);
}
});
familyViewHolder.deleteButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(context );
builder.setTitle("Delete");
builder.setMessage("Are you sure you want to delete this one ")
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
RemoveFamilyMember(position);
}
}).setNegativeButton("NO", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
builder.setCancelable(true);
}
});
AlertDialog alert=builder.create();
alert.show();
}
});
}
you can try something like this I think this might work, I haven't tested it but I think that making a new adapter everytime that the edittext has something in it is a bad idea. and if you get to the point back to where the query is equal to "" empty string then you should make the fileterd list back into the whole list which I didn't put in there
public class FamilyActivity extends AppCompatActivity {
RecyclerView recyclerView;
FamilyAdapter familyAdapter;
Button add_family;
EditText search;
List<Family> familyList;
List<Family> filteredList;
String patientID = "";
FamilyAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_family);
add_family=(Button)findViewById(R.id.add);
search =(EditText)findViewById(R.id.search);
familyList = new ArrayList<>();
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
Bundle extras = getIntent().getExtras();
if (extras != null) {
patientID = extras.getString("ID");
}
loadFamilyList();
filteredList = new ArrayList<>(familyList);
//adding some items to our list
//creating recyclerView adapter
adapter = new FamilyAdapter(this, filteredList);
//setting adapter to recyclerView
recyclerView.setAdapter(adapter);
addTextListener();
}
public void addTextListener(){
search.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence query, int start, int before, int count) {
query = query.toString().toLowerCase();
filteredList = new ArrayList<>();
for (int i = 0; i < familyList.size(); i++) {
final String text = familyList.get(i).toString().toLowerCase();
if (text.contains(query)) {
filteredList.add(familyList.get(i));
}
}
recyclerView.removeAllViews();;
adapter.notifyDataSetChanged(); // data set changed
}
});
}
editTextSearch.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
filter(s.toString());
}
});
private void filter(String text) {
ArrayList<Model> newList = new ArrayList<>();
for (Model item : mModelList) {
if (item.getTitle().contains(text)){
newList.add(item);
}
}
yourAdapter.setFilter(newList);
}
I have an Activity where I enter a phone number and a message and when I click on the send Button, I want to display the message and number I entered in the layout of another Activity which has a RecyclerView. I have tried to use an Intent but it displays "NUMBER" and "NUMBER" in both TextViews.
This is some of the code below.
public class NewMessageActivity extends AppCompatActivity {
private String message, number;
private EditText mComposeMessage, mPhoneNumber;
private Button mSendButton, mCancelButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_message_layout);
mPhoneNumber = (EditText) findViewById(R.id.phone_number_et);
mComposeMessage = (EditText) findViewById(R.id.compose_et);
mSendButton = (Button) findViewById(R.id.send_button);
mCancelButton = (Button) findViewById(R.id.cancel_button);
number = mPhoneNumber.getText().toString();
message = mComposeMessage.getText().toString();
mSendButton.setOnClickListener(mButtonClickListener);
mCancelButton.setOnClickListener(mButtonClickListener);
}
private View.OnClickListener mButtonClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.send_button:
Intent intent = new Intent(v.getContext(), SentActivity.class);
intent.putExtra(getString(R.string.key_message), message);
intent.putExtra("NUMBER", number);
startActivity(intent);
break;
case R.id.cancel_button:
break;
}
}
};
}
This is my Adapter
public class SentMessageAdapter extends RecyclerView.Adapter<SentMessageAdapter.MessageHolder> {
private List<String> mMessages;
public static class MessageHolder extends RecyclerView.ViewHolder {
private TextView mSentMessageTv;
private TextView mRecipientNumberTv;
private TextView mRecipientTv;
public MessageHolder(View v){
super(v);
mSentMessageTv = (TextView) v.findViewById(R.id.sent_message_tv);
mRecipientNumberTv = (TextView) v.findViewById(R.id.recipient_number_tv);
mRecipientTv = (TextView) v.findViewById(R.id.recipient_tv);
}
}
public SentMessageAdapter(List<String> messages){
mMessages = messages;
}
#Override
public MessageHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.sent_list_item, parent, false);
MessageHolder vH = new MessageHolder(v);
return vH;
}
#Override
public void onBindViewHolder(MessageHolder holder, int position) {
holder.mSentMessageTv.setText(mMessages.get(position));
holder.mRecipientNumberTv.setText(mMessages.get(position));
holder.mRecipientTv.setText(R.string.to);
}
#Override
public int getItemCount() {
return mMessages.size();
}
}
Activity where the text should be displayed
public class SentActivity extends AppCompatActivity {
private static final String LOG_TAG = SentActivity.class.getSimpleName();
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
final ArrayList<String> messages = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.message_recycler_list);
Bundle extras = getIntent().getExtras();
String message = null;
if (extras != null){
message = extras.getString(String.valueOf(R.string.key_message), String.valueOf("NUMBER"));
}
if (message == null){
message = "text";
}
Log.d(LOG_TAG, message);
messages.add(0, message);
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
mRecyclerView = (RecyclerView) findViewById(R.id.message_recycler_view);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new SentMessageAdapter(messages);
mRecyclerView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
}
}
Layout for the Activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="#+id/sent_message_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
tools:text="Hello world"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<TextView
android:id="#+id/recipient_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="#string/to"/>
<TextView
android:id="#+id/recipient_number_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:paddingRight="4dp"
android:paddingEnd="4dp" />
</LinearLayout>
</LinearLayout>
You're accessing phone number edit text in onCreate;
number = mPhoneNumber.getText().toString();
And it will be set to whatever your text in XML (It's set to NUMBER I guess). You need to access this after user entered text, so put this line in on click listener.
Get message and number value in onClick method not onCreate
switch (id) {
case R.id.send_button:
number = mPhoneNumber.getText().toString();
message = mComposeMessage.getText().toString();
Intent intent = new Intent(v.getContext(), SentActivity.class);
intent.putExtra(getString(R.string.key_message), message);
intent.putExtra("NUMBER", number);
startActivity(intent);
break;
}
Hope this will help you.
You are Not getting value that you entered is because you are accessing edittext values in onCreate method where it has default value so you should use
number = mPhoneNumber.getText().toString();
message = mComposeMessage.getText().toString();
this in onClick Methods
private View.OnClickListener mButtonClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.send_button:
number = mPhoneNumber.getText().toString();
message = mComposeMessage.getText().toString();
Intent intent = new Intent(v.getContext(), SentActivity.class);
intent.putExtra(getString(R.string.key_message), message);
intent.putExtra("NUMBER", number);
startActivity(intent);
break;
case R.id.cancel_button:
break;
}
}
};
My mistake. I have fixed it now. I created a POJO class
public class Message {
private String mMessage;
private String mNumber;
public Message(String number, String message){
mNumber = number;
mMessage = message;
}
public String getMessage() {
return mMessage;
}
public String getNumber() {
return mNumber;
}
}
Then I changed the onBindViewHolder() to
#Override
public void onBindViewHolder(MessageHolder holder, int position) {
holder.mSentMessageTv.setText(mMessages.get(position).getMessage());
holder.mRecipientNumberTv.setText(mMessages.get(position).getNumber());
holder.mRecipientTv.setText(R.string.to);
}
I also changed to
String message = null;
String number = null;
if (extras != null){
message = extras.getString(String.valueOf("MESSAGE"));
number = extras.getString(String.valueOf("NUMBER"));
}
messages.add(new Message(number, message));
Finally, I changed all generics to
<Message>
I am doing one application. In that i need to search the recycler item and once the user selects item from recycler then it should be set as a tag to that edit text. I did this from this https://android-arsenal.com/details/1/3581, but its not working properly. Can any help me how can i achieve the searching the items from recycler view and set it as a edit tag for that selected item.
This is the screen for reference.
I am doing like this
public class ActivityTagFriends extends BaseActivity implements TagsEditText.TagsEditListener, View.OnClickListener {
TextView tv_cancel, tv_title, tv_Done;
RecyclerView rv_TagFriends;
private TagsEditText mTagsEditText;
private List<String> list = new ArrayList<String>();
TagFriendsAdapter mAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tag_friends);
tv_cancel = (TextView) findViewById(R.id.tvCancel);
tv_cancel.setText("Cancel");
tv_cancel.setTextColor(getResources().getColor(R.color.red));
tv_title = (TextView) findViewById(R.id.tvTitle);
tv_title.setText("Tag Friends");
tv_title.setTextColor(getResources().getColor(R.color.black));
tv_Done = (TextView) findViewById(R.id.tvDone);
tv_Done.setText("Done");
tv_Done.setTextColor(getResources().getColor(R.color.red));
rv_TagFriends= (RecyclerView) findViewById(R.id.rv_TagFriends);
mTagsEditText = (TagsEditText) findViewById(R.id.tagsEditText);
mTagsEditText.setHint("Search");
mTagsEditText.setTagsListener(this);
mTagsEditText.setTagsWithSpacesEnabled(true);
mTagsEditText.setAdapter(new ArrayAdapter<>(this,
R.layout.tag_friends_row, R.id.tv_TagName,list));
mTagsEditText.setThreshold(1);
rv_TagFriends.setHasFixedSize(true);
rv_TagFriends.setLayoutManager(new LinearLayoutManager(this));
countryList(); // in this method, Create a list of items.
// call the adapter with argument list of items and context.
// mAdapter = new TagFriendsAdapter(list,this);
// rv_TagFriends.setAdapter(mAdapter);
addTextListener();
}
// this method is used to create list of items.
public void countryList(){
list.add("Afghanistan");
list.add("Albania");
list.add("Algeria");
list.add("Bangladesh");
list.add("Belarus");
list.add("Canada");
list.add("Cape Verde");
list.add("Central African Republic");
list.add("Denmark");
list.add("Dominican Republic");
list.add("Egypt");
list.add("France");
list.add("Germany");
list.add("Hong Kong");
list.add("India");
list.add("Iceland");
}
public void addTextListener(){
mTagsEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence query, int start, int before, int count) {
query = query.toString().toLowerCase();
final List<String> filteredList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
final String text = list.get(i).toLowerCase();
if (text.contains(query)) {
filteredList.add(list.get(i));
}
}
rv_TagFriends.setLayoutManager(new LinearLayoutManager(ActivityTagFriends.this));
mAdapter = new TagFriendsAdapter(filteredList, ActivityTagFriends.this);
rv_TagFriends.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
// data set changed
}
});
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
// mTagsEditText.showDropDown();
// data set changed
}
}
#Override
public void onClick(View v) {
}
#Override
public void onTagsChanged(Collection<String> tags) {
}
#Override
public void onEditingFinished() {
}
}
Thanks in advance.
Okay I got your problem use this code
Your activity layout(activity_main.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:TagsEditText="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="mabbas007.myapplication.MainActivity">
<mabbas007.tagsedittext.TagsEditText
android:id="#+id/tagsEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
TagsEditText:allowSpaceInTag="true"
TagsEditText:tagsBackground="#drawable/square_default"
TagsEditText:tagsCloseImageRight="#drawable/tag_close" />
<TextView
android:background="#android:color/darker_gray"
android:padding="10dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Suggestion"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
adapter layout(adapter_item.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:padding="10dp"
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:background="#color/colorAccent"
android:layout_height="1dp"/>
</LinearLayout>
Activity code
public class MainActivity extends AppCompatActivity
implements TagsEditText.TagsEditListener {
RecyclerView rv_TagFriends;
private TagsEditText mTagsEditText;
private List<String> list = new ArrayList<String>();
TagFriendsAdapter mAdapter;
ArrayList<String > tags;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tags=new ArrayList<>();
rv_TagFriends= (RecyclerView) findViewById(R.id.rv);
mTagsEditText = (TagsEditText) findViewById(R.id.tagsEditText);
mTagsEditText.setHint("Search");
mTagsEditText.setTagsListener(this);
mTagsEditText.setTagsWithSpacesEnabled(true);
//mTagsEditText.setAdapter(mAdapter);
mTagsEditText.setThreshold(1);
rv_TagFriends.setHasFixedSize(true);
rv_TagFriends.setLayoutManager(new LinearLayoutManager(this));
countryList(); // in this method, Create a list of items.
// call the adapter with argument list of items and context.
// mAdapter = new TagFriendsAdapter(list,this);
// rv_TagFriends.setAdapter(mAdapter);
addTextListener();
}
// this method is used to create list of items.
public void countryList(){
list.add("Afghanistan");
list.add("Albania");
list.add("Algeria");
list.add("Bangladesh");
list.add("Belarus");
list.add("Canada");
list.add("Cape Verde");
list.add("Central African Republic");
list.add("Denmark");
list.add("Dominican Republic");
list.add("Egypt");
list.add("France");
list.add("Germany");
list.add("Hong Kong");
list.add("India");
list.add("Iceland");
}
public void addTextListener(){
mTagsEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence query, int start, int before, int count) {
query = query.toString().toLowerCase().trim();
if (query.toString().equals(""))
return;
if (tags.size()!=0)
query=query.toString().substring(query.toString().indexOf(tags.get(tags.size()-1).toLowerCase())+tags.get(tags.size()-1).toString().length()).trim();
if (query.toString().equals("")){
final List<String> filteredList = new ArrayList<>();
rv_TagFriends.setLayoutManager(new LinearLayoutManager(MainActivity.this));
mAdapter = new TagFriendsAdapter(filteredList, MainActivity.this);
rv_TagFriends.setAdapter(mAdapter);
}else {
final List<String> filteredList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
final String text = list.get(i).toLowerCase();
if (text.contains(query)) {
filteredList.add(list.get(i));
}
}
rv_TagFriends.setLayoutManager(new LinearLayoutManager(MainActivity.this));
mAdapter = new TagFriendsAdapter(filteredList, MainActivity.this);
rv_TagFriends.setAdapter(mAdapter);
}
}
});
}
#Override
public void onTagsChanged(Collection<String> tags) {
}
#Override
public void onEditingFinished() {
}
public class TagFriendsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
private List<String > data;
private MainActivity mainActivity;
public TagFriendsAdapter(List<String> data , MainActivity mainActivity) {
this.data = data;
this.mainActivity=mainActivity;
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_item, parent, false));
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
((MyViewHolder)holder).text.setText(data.get(position)+"");
((MyViewHolder)holder).text.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mainActivity.add(data.get(position)+"");
}
});
}
#Override
public int getItemCount() {
return data.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView text;
public MyViewHolder(View itemView) {
super(itemView);
text = (TextView) itemView.findViewById(R.id.text);
}
}
}
public void add(String s){
for (int i = 0; i < tags.size(); i++) {
if (s.equals(tags.get(i)))
return;
}
tags.add(s);
String [] tag=tags.toArray(new String [0]);
mTagsEditText.setTags(tag);
}
}