我想在按鈕單擊片段後顯示列表視圖。從JsonTask中顯示片段中的ListView
public class Price extends Fragment{
Button submit;
submit = (Button) v.findViewById(R.id.submit);
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ListView lvShareSummary;
lvShareSummary = (ListView)v.findViewById(R.id.listviewStatement);
new JSONTaskShare(v.getContext(), lvShareSummary).execute("http://localhost:8080/price/PriceList");
}
});
}
}
XML佈局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/relativeLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#eed369"
android:text="Submit"
android:textColor="#182237"
android:textSize="30sp"
android:id="@+id/submit"
android:layout_marginTop="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<ListView
android:id="@+id/listviewStatement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relativeLayout4"
android:padding="5dp" />
</RelativeLayout>
沒有點擊該按鈕列表視圖工作正常。但是我想在點擊按鈕後顯示列表視圖。
什麼是'v'並在返回從'onCreateView'看法? –
保持與列表視圖有關的每一件事onclick,只需將適配器設置爲listview按鈕onclick – Redman
你在哪裏設置適配器的列表? – Ezio