2015-12-17 18 views
5

voglio usare attività si estende ListActivity per PullToRefresh.But ho uso CustomActionBar Ecco perché utilizzando AppCompatActivity.How per risolvere questo issue.Thanks in AdvancedCome estende ListActivity dove AppCompatActivity in attività Android

public class CustomActionActivity extends ListActivity 

public class PullToRefreshActivity extends ListActivity { 
    private LinkedList<String> mListItems; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.pull_to_refresh); 

     // Set a listener to be invoked when the list should be refreshed. 
     ((PullToRefreshListView) getListView()).setOnRefreshListener(new PullToRefreshListView.OnRefreshListener() { 
      @Override 
      public void onRefresh() { 
       // Do work to refresh the list here. 
       new GetDataTask().execute(); 
      } 
     }); 

     mListItems = new LinkedList<String>(); 
     mListItems.addAll(Arrays.asList(mStrings)); 

     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, mListItems); 

     setListAdapter(adapter); 
    } 

Invece di questo:

public class CustomActionActivity extends AppCompatActivity 
+0

Mi dispiace ma ho difficoltà a capire la domanda. Puoi provare a chiarire? –

+0

Nella mia attività, PullToRefresh non funziona correttamente, quindi desidero utilizzare ListActivity. Vedi ho modificato il mio post con PullToRefreshActivity. –

+0

Considerare l'utilizzo di RecyclerView. Questa è la più recente api http://developer.android.com/reference/android/support/v7/widget/RecyclerView.html –

risposta

2

Se si desidera utilizzare ListView nella propria app, quindi utilizzarlo direttamente senza estendere ListActivity. Mi piace questo

public class PullToRefreshActivity extends AppCompatActivity { 
private LinkedList<String> mListItems; 
PullToRefreshListView listView; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.pull_to_refresh); 
    listView = (PullToRefreshListView) findViewById(R.id.list_view); 
    // Set a listener to be invoked when the list should be refreshed. 
    listView.setOnRefreshListener(new PullToRefreshListView.OnRefreshListener() { 
     @Override 
     public void onRefresh() { 
      // Do work to refresh the list here. 
      new GetDataTask().execute(); 
     } 
    }); 

    mListItems = new LinkedList<String>(); 
    mListItems.addAll(Arrays.asList(mStrings)); 

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, mListItems); 

    listView.setAdapter(adapter); 
} 
Problemi correlati