listview를 만들고있는데 10개 데이터가 먼저나오고 더보기를 클릭하면 10개가 더나오는식으로 만들려고 합니다
그래서 클릭 리스너에서 다시 실행시키니까
java.lang.IllegalStateException: Cannot execute task: the task has already been executed (a task can be executed only once)
이렇게 한번밖에 사용이 안된다고 나오더라구요 ㅠㅠ
뭘써야 가능할까요??
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.stunote, container, false);
stuListView = (ListView) view.findViewById(R.id.stunotepad_listview1);
View footer = inflater.inflate(R.layout.listview_footer,null,false);
stuListView.addFooterView(footer) ;
adapter = new ListViewAdapter();
stuListView.setAdapter(adapter);
task = new StunoteJsonReadTask(adapter);
try {
String resultTask = task.execute(url).get();
Log.e("msg : ",resultTask);
} catch (InterruptedException e) {
e.printStackTrace();
Log.e("msg : ","error");
} catch (ExecutionException e) {
e.printStackTrace();
Log.e("msg : ","error");
}
Button addButton = (Button) footer.findViewById(R.id.addItem);
addButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try {
String resultTask = task.execute(url).get();
Log.e("msg : ",resultTask);
} catch (InterruptedException e) {
e.printStackTrace();
Log.e("msg : ","error");
} catch (ExecutionException e) {
e.printStackTrace();
Log.e("msg : ","error");
}
}
});
public class StunoteJsonReadTask extends AsyncTask<String,Void,String> {
String errorString = null;
int index;
ListViewAdapter adapter;
StunoteJsonReadTask(ListViewAdapter adapter){
index = 10;
this.adapter = adapter;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
try{
JSONObject jsonResponse = new JSONObject(result);
JSONArray jsonMainNode = jsonResponse.optJSONArray("major_document");
for(int i = index-10;i<index;i++)
{
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
String document_srl = jsonChildNode.optString("document_srl");
String title = jsonChildNode.optString("title");
String content = jsonChildNode.optString("content");
String regDate = jsonChildNode.optString("regdate");
String readed_count = jsonChildNode.optString("readed_count");
String commentCount = jsonChildNode.optString("comment_count");
String nick_name = jsonChildNode.optString("nick_name");
regDate = regDate.substring(0,4) + '-' + regDate.substring(4,6) + '-' + regDate.substring(6,8);
adapter.addItem(document_srl,title,content,regDate,readed_count,commentCount,nick_name);
}
index += 10;
adapter.notifyDataSetChanged();
}catch(JSONException e){
Log.e("msg : ","JSON 오류");
}