-2
私のリストビューに問題があります。クリアボタンをクリックすると私のリストはクリアされます(明らかに)が、私のリストはここでクリアされていません。ここでリストビューがクリアされないのはなぜですか?
MainClass
public class MainActivity extends AppCompatActivity {
ArrayList<SearchResults> searchResults;
private FloatingActionButton add;
private FloatingActionButton clear;
ArrayList<SearchResults> results = new ArrayList<SearchResults>();
final Context context = this;
String time1, people1, description1, mDate, hour, minute, MeridiemIndicator, dateNumber;
int Year, Month, Day, Hour, Minute;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
searchResults = new ArrayList<SearchResults>();
setContentView(R.layout.activity_main);
final ListView lv1 = (ListView) findViewById(R.id.ListView);
final CustomAdapter myAdapter = new CustomAdapter(context, R.layout.custom_row_view, results);
lv1.setAdapter(myAdapter);
add = (FloatingActionButton) findViewById(R.id.add);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
dialogMethod(lv1);
}
});
lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CustomAdapter adapter = (CustomAdapter) parent.getAdapter();
adapter.remove(results.get(position));
adapter.notifyDataSetChanged();
}
});
lv1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long l) {
CustomAdapter adapter = (CustomAdapter) parent.getAdapter();
adapter.remove(results.get(position));
adapter.notifyDataSetChanged();
dialogMethod(lv1);
return false;
}
});
clear = (FloatingActionButton) findViewById(R.id.clear);
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
results.clear();
myAdapter.notifyDataSetChanged();
}
});
}
private ArrayList<SearchResults> GetSearchResults() {
SearchResults sr1 = new SearchResults();
sr1.setName(" Meeting With: " + people1);
sr1.setTimeOfMeeting(" Starts At: " + time1);
sr1.setDescription(" Details: " + description1);
sr1.setDate(" Date: " + mDate);
sr1.setDateNumber(dateNumber);
results.add(sr1);
Collections.sort(results, new Comparator<SearchResults>() {
public int compare(SearchResults x, SearchResults y) {
return Integer.parseInt(x.getDateNumber()) - Integer.parseInt(y.getDateNumber());
}
});
return results;
}
ありがとうございました、私のカスタムアダプターは、より具体的な問題だけで浮動アクションボタン下のmainメソッドでは「明らか」である
public class CustomAdapter extends ArrayAdapter {
private static ArrayList<SearchResults> searchArrayList;
private LayoutInflater mInflater;
public CustomAdapter(Context context, int custom_row_view, ArrayList<SearchResults> results) {
super(context,custom_row_view,results);
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row_view, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView.findViewById(R.id.name);
holder.txtTimeOfMeeting = (TextView) convertView.findViewById(R.id.timeOfMeeting);
holder.txtDescription = (TextView) convertView.findViewById(R.id.description);
holder.txtDate = (TextView) convertView.findViewById(R.id.date);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtName.setText(searchArrayList.get(position).getName());
holder.txtTimeOfMeeting.setText(searchArrayList.get(position).getTimeOfMeeting());
holder.txtDescription.setText(searchArrayList.get(position).getDescription());
holder.txtDate.setText(searchArrayList.get(position).getDate());
return convertView;
}
static class ViewHolder {
TextView txtName;
TextView txtTimeOfMeeting;
TextView txtDescription;
TextView txtDate;
}
}
です。再びありがとうございます
それは働きました!非常にありがとうございます – jordan
あなたの問題を解決した場合は、回答を受け入れます – sasikumar
私は8分以上待たなければなりませんが、間違いありません – jordan