У меня есть небольшой фрагмент кода, который является классом ListActivity
Затем я динамически заполняю этот список, используя SimpleAdaptor. Каждая строка списка имеет 3 просмотра текста
Теперь я хочу изменить гарнитуру текста в этом ListView, но когда я тоже пытаюсь это сделать, я получаю исключение нулевого указателя. Кто-нибудь может помочь, пожалуйста?
Ниже приведен код
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import android.graphics.Typeface;
import android.widget.TextView;
public class Test extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
// final ArrayList<String> todoItems = new ArrayList<String>();
// Create the array adapter to bind the array to the listview
SimpleAdapter notes = new SimpleAdapter(
this,
list,
R.layout.list_row_view,
new String[] { "line1","line2","line3" },
new int[] { R.id.text1, R.id.text2,R.id.text3 } );
setListAdapter( notes );
Typeface tf = Typeface.createFromAsset(getResources().getAssets(),"tahoma.ttf");
TextView tv = (TextView) findViewById(R.id.text1);
tv.setTypeface(tf);
HashMap<String,String> item = new HashMap<String,String> ();
item.put( "line1","A" );
item.put( "line2","B" );
item.put("line3","C");
list.add(item);
HashMap<String,String> item1 = new HashMap<String,String> ();
item1.put( "line1","A" );
item1.put( "line2","B" );
item1.put( "line3","C" );
list.add( item1 );
}
}
Линия
TextView tv = (TextView) findViewById(R.id.text1);
выдает исключение нулевого указателя