我的listView有问题,当我点击清除按钮时,我希望我的列表清除(显然)但由于某种原因我的清单未清除这里是下面的代码,任何帮助将不胜感激。谢谢
MainClass
@Component
public class CamelS3HeadersProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
SimpleBuilder simpleBuilder = new SimpleBuilder("${file:name}");
String fileName = simpleBuilder.evaluate(exchange, String.class);
//do some logic and set headers
}
}
这是我的自定义适配器
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;
}
问题更具体地说是浮动动作按钮“清除”下面的主要方法。再次谢谢你
答案 0 :(得分:0)
再次清除列表setadapter之后。
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
results.clear();
CustomAdapter myAdapter = new CustomAdapter(context, R.layout.custom_row_view, results);
lv1.setAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
}
});
OR
清除适配器
myAdapter.clear();
myAdapter.notifyDataSetChanged();