当我单击ButtonSearchClickListener
ArrayList值输入hide(TextView
)时,此结果如何输入RecyclerView
Adapter
getData()
public class MainActivity extends AppCompatActivity {
EditText editFilename, editName, editGender, editAge, editSearch;
Button addBtn, addFile, btnSearch;
TextView hide;
private RecyclerView recyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager layoutManager;
ArrayList<String> arrayName = new ArrayList<String>(5);
ArrayList<String> arrayGender = new ArrayList<String>(5);
ArrayList<Integer> arrayAge = new ArrayList<Integer>(5);
ArrayList arrayUser = new ArrayList<>(5);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String []filter = {};
editName = (EditText) findViewById(R.id.editName);
editGender = (EditText) findViewById(R.id.editGender);
editAge = (EditText) findViewById(R.id.editAge);
editSearch = (EditText) findViewById(R.id.editSearch);
addBtn = (Button) findViewById(R.id.addBtn);
btnSearch = (Button) findViewById(R.id.btnSearch);
RecyclerView rv= (RecyclerView) findViewById(R.id.rv);
rv.setLayoutManager(new LinearLayoutManager(this));
MyAdapter adapter = new MyAdapter(this,getData());
rv.setAdapter(adapter);
hide = (TextView)findViewById(R.id.hide);
addBtn.setOnClickListener(new ButtonAddClickListener(this));
btnSearch.setOnClickListener(new ButtonSearchClickListener(this));
}
class ButtonAddClickListener implements View.OnClickListener {
Context context;
public ButtonSearchClickListener(Context context) {
this.context = context;
}
@Override
public void onClick(View v) {
String match = editSearch.getText().toString();
for (int i = 0; i < arrayName.size(); i++) {
if (match != null && match.equals(arrayName.get(i))) {
for (int j = 0; j < arrayUser.size(); j++) {
hide.setText(" 검색결과입니다 \n" + "\n" + "성명: " + arrayUser);
Log.d("name", "name" + hide);
}
} else if (match != null && match.equals(arrayGender.get(i))) {
for (int j = 0; j < arrayUser.size(); j++) {
hide.setText(" 검색결과입니다 \n" + "\n" + arrayUser);
Log.d("gender", "gender" + hide);
}
} else if ((match != null) && (Integer.valueOf(match) == Integer.valueOf(arrayAge.get(i)))) {
for (int j = 0; j < arrayUser.size(); j++) {
hide.setText(" 검색결과입니다 \n" + "\n" + arrayUser);
Log.d("age", "age" + hide);
}
} else {
Toast.makeText(MainActivity.this, "검색조건에 해당하는 정보가없습니다. 다시입력해주세요", Toast.LENGTH_SHORT).show();
}
}
}
}
// this recyclerview adapter code //
private ArrayList<String> getData(){
final ArrayList<String> userInfo = new ArrayList<>();
userInfo.clear();
if(hide !=null) {
String asd = String.valueOf(hide);
userInfo.add(asd);
}
return userInfo;
}