2 u010186884 u010186884 于 2014.11.03 21:03 提问

android大神求救。。。listView问题

package com.example.listviewdemo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

RefreshListView listView;
MyAdapter myAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    listView=(RefreshListView)findViewById(R.id.listView);
    myAdapter=new MyAdapter(MainActivity.this);
    listView.setAdapter(myAdapter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

package com.example.listviewdemo;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListAdapter;
import android.widget.ListView;

public class RefreshListView extends ListView{

public RefreshListView(Context context) {
    super(context);

}
public RefreshListView(Context context, AttributeSet attrs) {
    super(context, attrs);

}
public RefreshListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

}
@Override
public void setAdapter(ListAdapter adapter) {
    super.setAdapter(adapter);
}

}

package com.example.listviewdemo;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter{
private int count=15;
private Context context;

public MyAdapter(Context context){
    this.context=context;
}
@Override
public int getCount() {
    return count;
}

@Override
public Object getItem(int position) {

    return position;
}

@Override
public long getItemId(int position) {

    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LinearLayout lay=new LinearLayout(context);
    lay.setOrientation(0);
    ImageView image=new ImageView(context);
    image.setImageResource(R.drawable.ic_launcher);
    TextView text=new TextView(context);
    text.setText("第"+position+"个");
    lay.addView(image);
    lay.addView(text);
    return lay;
}

}

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

为什么以上代码运行会直接退出。。。。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!