Last active
August 29, 2015 14:03
-
-
Save zhaochunqi/6ab74d0c65bc46a5fc91 to your computer and use it in GitHub Desktop.
Adapter--BaseAdapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
tools:context="cn.zhaochunqi.testadapter.app.JumpToAdapter"> | |
<LinearLayout | |
android:orientation="vertical" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/linearLayout" | |
android:layout_centerInParent="true"> | |
<Button | |
android:onClick="click_to_BaseAdapter" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="BaseAdapter" | |
android:id="@+id/button" | |
/> | |
<Button | |
android:onClick="click_to_SimpleAdapter" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="SimpleAdapter" | |
android:id="@+id/button2" | |
/> | |
<Button | |
android:onClick="click_to_ArrayAdapter" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="ArrayAdapter" | |
android:id="@+id/button3" | |
/> | |
</LinearLayout> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cn.zhaochunqi.testadapter.app; | |
import android.os.Bundle; | |
import android.support.v7.app.ActionBarActivity; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseAdapter; | |
import android.widget.ListView; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by alex on 6/26/14. | |
*/ | |
public class TestBaseAdapter extends ActionBarActivity { | |
private ListView lv_base; | |
private List<String> stringList = new ArrayList<String>(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
getSupportActionBar().hide(); | |
setContentView(R.layout.activity_test_baseadapter); | |
lv_base = (ListView)findViewById(R.id.lv_testbaseadapter); | |
makelist(); | |
lv_base.setAdapter(new MyBaseListViewAdapter()); | |
} | |
private void makelist() { | |
String s; | |
for(int i=0;i<100;i++) { | |
s = "Hello World this is the " +i+"th number !"; | |
stringList.add(s); | |
} | |
} | |
//listView的Adapter,就显示一个普通的文本。 | |
private class MyBaseListViewAdapter extends BaseAdapter { | |
@Override | |
public int getCount() { | |
return stringList.size(); | |
} | |
@Override | |
public Object getItem(int position) { | |
return null; | |
} | |
@Override | |
public long getItemId(int position) { | |
return 0; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
TextView tv = new TextView(TestBaseAdapter.this); | |
String s = stringList.get(position); | |
tv.setText(s); | |
return tv; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment