一个利用ListView的工程不能运行?

张景喻 发布于 2013/10/30 12:12
阅读 128
收藏 0

下面这段代码在编译器上是没有错的,但是下载到android虚拟机上就不能使用了,很简单的代码,我也在manifest中注册了的。新手,求解答,谢谢!

package dd.frist;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class two extends Activity {
public ListView listview;
public TextView text;
String[] s1 = {"一杯","二杯","三杯","四杯","五杯","大家","no"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.two);
LinearLayout two = (LinearLayout)findViewById(R.id.root2);
text = (TextView)findViewById(R.id.mytext);
text.setText("two");

listview = (ListView)findViewById(R.id.mylistview);
ArrayAdapter<String> list1 = new ArrayAdapter<String>(this, R.layout.two,s1);
listview.setAdapter(list1);
listview.setCacheColorHint(000000000);
listview.setFastScrollEnabled(true);
listview.setFadingEdgeLength(100);
listview.setOnScrollListener(new ListView.OnScrollListener()
{

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
text.setText(s1[firstVisibleItem - 2]);

}

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub

}

});
listview.setOnItemClickListener(new ListView.OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
listview.setSelectionFromTop(arg2 - 2, 0);
text.setText(s1[arg2]);

}


});

listview.setOnItemSelectedListener(new ListView.OnItemSelectedListener(){

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
text.setText(s1[arg2]);
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}
});

}
}

下面是布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:id="@+id/root2"
 >
 <TextView
     android:id = "@+id/mytext"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
    ></TextView>
 <ListView
     android:id = "@+id/mylistview"
     android:layout_width="90px"
     android:layout_height="252px"
     android:layout_y = "70px"
     android:scrollbars = "none"
     android:dividerHeight="1px"
     android:layout_x = "100px"
     ></ListView>

</LinearLayout>

 

加载中
返回顶部
顶部