2015-01-21 4 views
1

Я хочу набор фон для ListView, это фотографии показать цельКак установить фон в listview?

photo one : this is the xml file , show background ! но photo two see!! when run don't show background

это код в Java файл

public class a extends ListActivity { 

String[] listItems = {"سه‌ره‌تای ئیمان ـ باوه‌ڕ ـ وتنی: (لا اله الا الله)یه‌","فه‌رمانم پێكراوه‌ بجه‌نگم له‌گه‌ڵ خه‌ڵكیدا هه‌تا ده‌ڵێن (لا اله الا الله)"}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
// TODO Auto-generated method stub 
super.onCreate(savedInstanceState); 

setListAdapter(new ArrayAdapter<String>(a.this, 
android.R.layout.simple_list_item_1, listItems)); 

} 


@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
// TODO Auto-generated method stub 
super.onListItemClick(l, v, position, id); 

if (position == 0) { 
Intent intent = new Intent(this, a_a_activity.class); 
startActivity(intent); 
} else if (position == 1) { 
Intent intent = new Intent(this, a_a_activity.class); 
startActivity(intent); 
} 

ответ

0

Очень просто. по getListView() вы можете это сделать.

как этот код:

import android.app.ListActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class a extends ListActivity { 

String[] listItems = { 
     "سه‌ره‌تای ئیمان ـ باوه‌ڕ ـ وتنی: (لا اله الا الله)یه‌", 
     "فه‌رمانم پێكراوه‌ بجه‌نگم له‌گه‌ڵ خه‌ڵكیدا هه‌تا ده‌ڵێن (لا اله الا الله)" }; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 

    setListAdapter(new ArrayAdapter<String>(a.this, 
      android.R.layout.simple_list_item_1, listItems)); 
    // Get Active listView 
    getListView().setBackground(R.drawable.your_background); 

} 

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    // TODO Auto-generated method stub 
    super.onListItemClick(l, v, position, id); 

    if (position == 0) { 
     // Intent intent = new Intent(this, a_a_activity.class); 
     // startActivity(intent); 
    } else if (position == 1) { 
     // Intent intent = new Intent(this, a_a_activity.class); 
     // startActivity(intent); 
    } 
} 
} 

при использовании ListActivity вы можете получить ваш ListView с помощью вызова метода:

ListView list = getListView(); // OR you can do 
ListView list = (ListView)findViewById(android.R.id.list); //consider the android prefix.. 
0

Вы можете получить доступ к ListView в пределах ListActivity с использованием getListView()

getListView().setBackgroundColor(0xFFDED2BE); 
0

Вы можете сделать это с помощью метода getListView().

public class a extends ListActivity { 

String[] listItems = {"سه‌ره‌تای ئیمان ـ باوه‌ڕ ـ وتنی: (لا اله الا الله)یه‌","فه‌رمانم پێكراوه‌ بجه‌نگم له‌گه‌ڵ خه‌ڵكیدا هه‌تا ده‌ڵێن (لا اله الا الله)"}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
// TODO Auto-generated method stub 
super.onCreate(savedInstanceState); 

setListAdapter(new ArrayAdapter<String>(a.this, 
android.R.layout.simple_list_item_1, listItems)); 

//getListView.setBackground(getDrawable(R.drawable.your_background_image)); 


} 


@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
// TODO Auto-generated method stub 
super.onListItemClick(l, v, position, id); 

if (position == 0) { 
Intent intent = new Intent(this, a_a_activity.class); 
startActivity(intent); 
} else if (position == 1) { 
Intent intent = new Intent(this, a_a_activity.class); 
startActivity(intent); 
} 
0
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 

    setListAdapter(new ArrayAdapter<String>(a.this, 
      android.R.layout.simple_list_item_1, listItems)); 
    // Get Active listView 
    getListView().setBackgroundResource(R.drawable.background_file_name); 

} 
Смежные вопросы