您好我的第一篇文章我的第一個Android應用程序的更高級的應用程序...我知道這個主題在這裏提到,谷歌知道很多例子,但他們不是什麼即時通訊形式;(從重載的ArrayAdapter getView不being從AsyncTask/onPostExecute調用
我承認我是一個n00000b ...在Android編碼方面...我開始...前幾天,請原諒我:)
問題是我的listview元素沒有被填充。應用程序編譯和運行沒有錯誤,但它沒有午餐getView。從我閱讀網絡上...我需要這與它的內容顯示我心愛的ListView ...
請幫助:)
package com.test.stackParser;
public class StackParserActivity extends Activity {
/** Called when the activity is first created. */
private ProgressDialog pd;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//final TextView tv = (TextView) findViewById(R.id.textView1);
//tv.setMovementMethod(new ScrollingMovementMethod());
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(myListener);
}
private OnClickListener myListener = new OnClickListener() {
public void onClick(View v) {
pd = ProgressDialog.show(StackParserActivity.this, "Working...", "request to server", true, false);
new ParseSite().execute("http://multikino.pl/pl/repertuar/warszawa-ursynow/2011-09-02/");
}
};
private class ParseSite extends AsyncTask<String, Void, List<String>> {
protected List<String> doInBackground(String... arg) {
List<String> output = new ArrayList<String>();
try
{
HtmlHelper hh = new HtmlHelper(new URL(arg[0]));
List<TagNode> links = hh.getLinksByClass("title");
for (Iterator<TagNode> iterator = links.iterator(); iterator.hasNext();)
{
TagNode divElement = (TagNode) iterator.next();
output.add(divElement.getText().toString());
}
Log.d("dupa", "siteParsed");
}
catch(Exception e)
{
e.printStackTrace();
}
return output;
}
protected void onPostExecute(List<String> output) {
pd.dismiss();
Log.d("dupa", "postExecute");
ListView listview = (ListView) findViewById(R.id.listViewData);
//listview.setAdapter(new ArrayAdapter<String>(StackParserActivity.this, android.R.layout.simple_list_item_1 , output));
MyAdapter dupa = new MyAdapter(StackParserActivity.this, android.R.layout.simple_list_item_1, R.id.movieTitle, output);
dupa.notifyDataSetChanged();
listview.setAdapter(dupa);
dupa.notifyDataSetChanged();
}
}
private class MyAdapter extends ArrayAdapter<string> {
String[] tabObj;
public MyAdapter(Context context, int resource, int textViewResourceId, List<String> output) {
super(context, resource, textViewResourceId);
tabObj = output.toArray(new String[]{});
Log.d("dupa", tabObj[2].toString());
notifyDataSetChanged();
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Log.d("dupa", "!!!!getView");
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.row_layout,parent,false);
TextView tv = (TextView) row.findViewById(R.id.movieTitle);
tv.setText(tabObj[position]);
//Button buton1 = (Button) row.findViewById(R.id.buttonInfo);
//Button button2 = (Button) row.findViewById(R.id.buttonReserve);
return super.getView(position, convertView, parent);
}
};
}
我按照你的建議更改了代碼。 Iam現在返回行,我刪除了所有notifyDatasetChanged(),但仍然沒有。 getView方法不吃午餐。 Log.d(「dupa」,「!!!! getView」);不會輸出任何內容到Log:/ – mentis
您應該在適配器中重寫'getCount'。 – Ronnie
是的:D thx非常非常! – mentis