我想在按钮单击片段后显示列表视图。从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