Очень плохо знаком с Android Studio и пытается решить следующее;У меня есть 2 вида списка, и я хотел бы «onClick» добавить элемент из listView1 в listView2.
Элемент, по которому щелкнули (и добавили), должен быть сохранен из ArrayList1 -> ArrayList2.
Как мне это сделать?
Скриншот макета. https://imgur.com/a/7nJ0uX9
Я пытался решить эту проблему, следуя инструкциям на YouTube, но, похоже, они не охватывают мою проблему явно.
public class SearchFilter extends AppCompatActivity {
private static final String TAG = "SearchActivity";
private ArrayAdapter adapter1;
private ArrayAdapter adapter2;
private ListView listView1;
private ListView listView2;
private String names1[] = new String[] {"mitch", "luke", "samantha", "jessi", "janelle", "jordan", "rick"};
private String [] names2 = new String[names1.length];
private List name1List = new ArrayList();
private List name2List = new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_filter);
for(String a : names1){
name1List.add(a);
}
for (String b : names2){
name2List.add(b);
}
listView1 = (ListView) findViewById(R.id.listView1);
listView2 = (ListView) findViewById(R.id.listView2);
adapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, name1List);
listView1.setAdapter(adapter1);
adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, name2List);
listView2.setAdapter(adapter2);
EditText theFilter = (EditText) findViewById(R.id.searchFilter);
Log.d(TAG, "onCreate: Started");
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
name2List.add(name1List.get(position));
adapter2.notifyDataSetChanged();
}
});
theFilter.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
(SearchFilter.this).adapter1.getFilter().filter(charSequence);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
}
}
Logcat:
2019-10-16 06:16:38.843 29135-29191/? E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2019-10-16 06:48:39.276 29135-29191/? E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2019-10-16 07:52:39.608 29135-29191/? E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2019-10-16 10:00:39.972 29135-29191/? E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2019-10-16 10:00:41.539 536-536/? E/FirebaseInstanceId: Failed to start service while in background: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.firebase.INSTANCE_ID_EVENT pkg=com.google.android.apps.messaging cmp=com.google.android.apps.messaging/.fcm.BugleFirebaseInstanceIDService (has extras) }: app is in background uid UidRecord{7000ddf u0a54 RCVR idle change:idle|uncached procs:1 seq(0,0,0)}
2019-10-16 12:12:47.116 3132-3205/com.google.android.youtube E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2019-10-16 12:13:17.318 3132-3205/com.google.android.youtube E/FirebaseInstanceId: Token retrieval failed: QUOTA_EXCEEDED
2019-10-16 12:14:17.534 3132-3205/com.google.android.youtube E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2019-10-16 12:16:17.706 3132-3205/com.google.android.youtube E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2019-10-16 12:20:36.753 3132-3205/com.google.android.youtube E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2019-10-16 12:28:44.679 3132-3205/com.google.android.youtube E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2019-10-16 12:45:19.843 3132-3205/com.google.android.youtube E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER