Top Picks

   
December 1, 2012

 

Very simple adapter rearrangement technic in Android

 

I have a search engine that perform search in a pre-defined strings. I want to show the list of the result in a custom font rather then android default! I also have a simple custom font app. But cannot make a good adapter for this.

This is Custom Font App

/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = (TextView)findViewById(R.id.tv); Typeface cFont = Typeface.createFromAsset(getAssets(), "fonts/jcc.ttf"); tv.setTypeface(cFont); <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:textSize="18sp" android:id="@+id/tv" />

This is product search app:

public class ProductList extends Activity {

// List view private ListView lv; // Listview Adapter ArrayAdapter<String> adapter; // Search EditText EditText inputSearch; // ArrayList for Listview ArrayList<HashMap<String, String>> productList; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_product_list); String asim02 = System.getProperty("line.separator"); String products[] = { "Apple" + asim02 +"Definition1", "Orange" + asim02 +"Definition2", "Banana"+ asim02 +"Definition3", "Onion"+ asim02 +"Definition4", }; lv = (ListView) findViewById(R.id.list_view); inputSearch = (EditText) findViewById(R.id.inputSearch); // Adding items to listview adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.p_list, products); lv.setAdapter(adapter); /** * Enabling Search Filter * */ inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { // When user changed the Text ProductList.this.adapter.getFilter().filter(cs);} @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub} @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub} <TextView android:textColor="?android:textColorPrimary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15sp" android:id="@+id/p_list" />

Please help to make the adapter!!! I am very new and cannot understand well!!! Want your kind help.

Image of ProductList app https://dl.dropbox.com/u/15065300/ProductList.png
(As a new user I am not allowed to give more image link)

Here is the two example Apps http://www.mediafire.com/?8hp1r1f6rsl53vr

 

Answer

You will have to use Custom ListView Adapter for this and set the font in its getView method.

Some Tutorials:
Tutorial 1
More Tuts

Professional Hosting fro Just Host

Filed under: Android Coding FAQ

Tags:

Comments

No Comments

Leave a reply