2010年6月アーカイブ
AndroidのListViewにFooterViewってのがあるらしいです。
使いかたは現在調べ中です。
何かわかったらここに書こうとおもってます。
つづき
ListViewの最後と最初にいったらレコードを追加するやり方がわかったのでサンプルを
残しておきます。
このやり方でよいかはよくわからないですが、動くのは動きます。。。
以下サンプル。
public class ListViewSample extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
for(String tmp : mStrings){
list.add(tmp);
}
setListAdapter(new MyListAdapter(this));
}
private class MyListAdapter extends BaseAdapter {
public MyListAdapter(Context context) {
mContext = context;
}
public int getCount() {
return list.size();
}
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv;
if (convertView == null) {
tv = (TextView) LayoutInflater.from(mContext).inflate(
android.R.layout.simple_expandable_list_item_1, parent, false);
} else {
tv = (TextView) convertView;
}
// 最後にいったら再度ListViewに追加
if(position == (this.getCount()-1)){
for(String tmp : mStrings){
list.add(tmp);
this.notifyDataSetChanged();
}
}
// 先頭にいったら再度ListViewに追加
if(position == 0){
int i = 0;
for(String tmp : mStrings){
list.add(i, tmp);
this.notifyDataSetChanged();
i++;
}
// さっきまでの場所を選択
setSelection(position + mStrings.length);
}
tv.setText(list.get(position));
return tv;
}
private Context mContext;
}
private ArrayList<String> list = new ArrayList<String>();
private String[] mStrings = {
"00000000001",
"00000000002",
"00000000003",
"00000000004",
"00000000005",
"00000000006",
"00000000007",
"00000000008",
"00000000009",
"00000000010",
"00000000011",
"99999999999"
};
}
以上です。
AndroidでJSONを扱ってみた。
AndroidでJSONを扱う際に使うクラスは前回同様「JSONObject」でこれを使えばなにも
考えずにJSON形式のデータから値を取得できます。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 画面に表示するため
TextView tv = (TextView)findViewById(R.id.TextView01);
String jsonData = "{\"ERR\":\"0\", \"MSG\":\"OK\"}";
JSONObject json;
try {
json = new JSONObject(jsonData);
tv.setText(json.getString("ERR") + " / " + json.getString("MSG"));
} catch (JSONException e) {
e.printStackTrace();
}
}
って感じで取得できます。
以上です。
関連
AndroidでJSONを扱ってみた。
AndroidでJSONを扱う際に使うクラスは「JSONObject」でこれを使えばなにも
考えずにJSONに形式にできちゃいます。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 画面に表示するため
TextView tv = (TextView)findViewById(R.id.TextView01);
Map
map.put("LOGIN_NAME", "shinn");
map.put("LOGIN_PASS", "xxxxxxxxx");
// JSON形式にするためMapを渡す
JSONObject json = new JSONObject(map);
// JSON形式の文字列
String jsonstr = json.toString();
// TextViewに表示
tv.setText(jsonstr);
}
って感じでさくっとできます。
以上です。次は送られてきたJSON形式データを取り込むところを書こうかなぁ。
関連
Windows 7でtomcatを動かそうとしたときにはまったのでメモしときます。
Windows 7ではTomcat6.0.21以上でしか動作しないようです。
このために結構な時間を使ったので・・・。
ちなみに自分はtomcat6.0.20でした。
おしい。。。
もうちょっと新しいのにしとけばw 以上です。
