したがって、私はListviewから要素をカスタマイズしてカスタムアダプタを作成しました。ここで要素がListViewのカスタムアダプタで表示されない
public class elementList extends BaseAdapter {
Context context;
String[] data;
private static LayoutInflater inflater = null;
public elementList(Context context, String[] data) {
this.context = context;
this.data = data;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return data.length;
}
@Override
public Object getItem(int position) {
return data[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if(vi == null)
vi = inflater.inflate(R.layout.task, null);
TextView text = (TextView)vi.findViewById(R.id.title);
Log.d("TAG", "DA");
text.setText(data[position]);
return vi;
}
}
は、私は(要素)私のアダプタを使用していますが、私が使用している場合、それは正常に動作していた場合、それは私のリストを表示されない理由を私は理解していない私の主な活動
private void showTasks(){
final ArrayList<String> taskList = new ArrayList<String>();
ListView listView = (ListView)findViewById(R.id.listView);
final List<String> tasks = new ArrayList<String>(taskList);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, tasks);
final elementList element = new elementList(this, tasks.toArray(new String[0]));
listView.setAdapter(element);
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference adress = database.getReference("users/" + user.getUid() + "/tasksList");
adress.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try{
if(dataSnapshot.getValue() != null){
Map<String, String> value = (Map<String, String>)dataSnapshot.getValue();
for (Map.Entry<String, String> entry : value.entrySet()){
tasks.add(entry.getValue());
Log.d("VALOARE", entry.getValue());
element.notifyDataSetChanged();
}
}
}
catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
ですarrayadapter。私はarrayadapterを使用している最初の画像において第2要素に
。私はそれがクラッシュしたり、何かエラーを出さないことを言及したい。
私は静的なレイアウトのインフレータが疑わしいと感じました。親ビューを 'inflate'メソッドに渡す方法についてはhttps://possiblemobile.com/2013/05/layout-inflation-as-intended/をチェックしてください。 – frozenkoi
'elementList''Adapter'をサポートする配列は決して変更/更新されません。空のときに 'tasks''List'の配列コピーを作成しますが、それ以降は配列を変更しないでください。 'List'はその配列に対して何もしません。カスタムの 'Adapter'を代わりに' List'にするのはどうでしょう。なぜなら、あなたは 'ArrayAdapter'と同じ方法でそれを更新できますか? –
あなたのtask.xmlのレイアウトを共有します –