2016-07-26 6 views
0

Ich kopierte Code und Klasse, die in Activity gut funktioniert haben (ich ändere meine Aktivitäten zu fragmentieren, um Tab zu verwenden). Aber in Fragment funktioniert es nicht. Es gibt keinen App Crush, aber keine Liste erscheint auf meinem Display. Ich habe bereits meine Datenbank überprüft, es hat richtig funktioniert. aber nichts auf meiner Liste. Bitte hilf mir. Unten ist mein Code.Mein benutzerdefiniertes ListView funktioniert nicht in Fragment

ListFragment.java

public class ListFragment extends android.support.v4.app.Fragment { 

DBHelper mydb; 
SQLiteDatabase db; 

Intent retent; 
private int amount; 
private String date; 
private String time; 
private String use; 
private ListView useList; 
private ArrayList<history> histories; 
private historyAdapter adapter; 
private String checker; 
private TextView upperBalance; 

private int position=4; 
private int onClickPosition; 
private int itemcount; 
private int amt=0; 

public boolean bottomViewActivate = false; 
public boolean monthlyActivate = true; 

private int bottomViewId =0; 
private TextView Arvitor; 
private FrameLayout frameArvitor; 
private ArrayList<history> historiesBackup; 

private int CurrentYearMonthInt=0; 
private int CurrentAddBalance=0; 
public Calendar c = Calendar.getInstance(); 
public SimpleDateFormat intform = new SimpleDateFormat("yyMM"); 
public SimpleDateFormat yearform = new SimpleDateFormat("yyyy"); 
public SimpleDateFormat monthform = new SimpleDateFormat("MM"); 
public SimpleDateFormat yearf = new SimpleDateFormat("yy"); 
int year = Integer.parseInt(yearform.format(c.getTime())); 
int month = Integer.parseInt(monthform.format(c.getTime())); 

public ListFragment() { 

} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.fragment_page2, container, false); 
    year = Integer.parseInt(yearform.format(c.getTime())); 
    month = Integer.parseInt(monthform.format(c.getTime())); 
    CurrentYearMonthInt=Integer.parseInt(intform.format(c.getTime())); 
    mydb = new DBHelper(getActivity()); 

    upperBalance = (TextView)rootView.findViewById(R.id.ListUpView); 
    if(mydb.numberOfRows()!=0) { 
     upperBalance.setText(" Current Balance : "+mydb.getRecentBalance()+"won"); 
    }else { 
     upperBalance.setText(" Balance : 0won"); 
    } 

    useList=(ListView) rootView.findViewById(R.id.listView); 
    histories = new ArrayList<history>(); 
    adapter = new historyAdapter(getActivity(), R.layout.listsublayout, histories); 
    useList.setAdapter(adapter); 
    getActivity().registerForContextMenu(useList); 
    histories=mydb.getAllUseList(bottomViewId,bottomViewActivate,monthlyActivate,CurrentYearMonthInt); 
    itemcount=mydb.numberOfRows(); 
    adapter.notifyDataSetChanged(); 

    return rootView; 
    } 
} 

Antwort

0

Gelöst ich dieses Problem.

Aber ich kann nicht verstehen, warum diese Lösung funktioniert. Wie auch immer, ich präsentiere, wie ich dieses Problem gelöst habe, für wen das gleiche Problem gelitten hat.

Ich änderte

Historien = mydb.getAllUseList (bottomViewId, bottomViewActivate, monthlyActivate, CurrentYearMonthInt);

zu

histories.addAll (mydb.getAllUseList (bottomViewId, bottomViewActivate, monthlyActivate, CurrentYearMonthInt));

Wer weiß, warum diese Lösung funktioniert, antworten Sie bitte auf meine Frage.