Created
November 3, 2009 16:38
-
-
Save hyoromo/225189 to your computer and use it in GitHub Desktop.
ListView03
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 jp.ne.hyoromo.android.DemoView03; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ArrayAdapter; | |
import android.widget.ImageView; | |
import android.widget.ListView; | |
import android.widget.TextView; | |
/** | |
* シンプルListView03<br> | |
* カスタマイズしているListView | |
* | |
* @author hyoromo | |
*/ | |
public class DemoView03 extends Activity { | |
private static Context mContext; | |
private static ListData[] mListData; | |
// アダプター設定リスト | |
private String[] mData = { "red", "yellow", "blue", "green", "pearl", "gold", "silver" }; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
mContext = getApplicationContext(); | |
// 独自アダプターの作成 | |
mListData = new ListData[mData.length]; | |
for (int i = 0; i < mData.length; i++) { | |
mListData[i] = new ListData(); | |
mListData[i].text = mData[i]; | |
mListData[i].icon = R.drawable.icon; | |
} | |
AdapterEx adapter = new AdapterEx(); | |
// リストビューの作成&アダプター設定 | |
ListView listView = (ListView) findViewById(R.id.list); | |
listView.setAdapter(adapter); | |
} | |
/** | |
* ArrayAdapterを拡張したクラス。 | |
* | |
* @author hyoromo | |
*/ | |
private class AdapterEx extends ArrayAdapter<Object> { | |
AdapterEx() { | |
super(mContext, R.layout.row, mListData); | |
} | |
// 画面に表示される毎に呼び出される | |
final public View getView(int position, View convertView, ViewGroup parent) { | |
View row = convertView; | |
if (row == null) { | |
LayoutInflater inflater = LayoutInflater.from(mContext); | |
row = inflater.inflate(R.layout.row, null); | |
} | |
TextView text = (TextView) row.findViewById(R.id.TextView01); | |
text.setText(mListData[position].text); | |
ImageView icon = (ImageView) row.findViewById(R.id.ImageView01); | |
icon.setImageResource(mListData[position].icon); | |
return row; | |
} | |
} | |
// Listがクリックされたら呼ばれる | |
public final void onListItemClick(ListView parent, View v, final int position, long id) { | |
} | |
/** | |
* Rowの中身 | |
* | |
* @author hyoromo | |
*/ | |
public final class ListData { | |
public String text; | |
public int icon; | |
} | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:orientation="vertical"> | |
<ListView | |
android:id="@+id/list" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:drawSelectorOnTop="false" /> | |
</LinearLayout> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content"> | |
<ImageView | |
android:id="@+id/ImageView01" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> | |
<TextView | |
android:id="@+id/TextView01" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment