我创建了一个可扩展列表,但是当我点击父级但它没有打开子组件并且它关闭它时。我不知道发生了什么错误。如果有人说我也提供快照。我尝试了很多东西但没有发生任何事情。我发生了所有这些事情bcoz添加滚动视图之前添加滚动视图这些工作完美。但不是它不工作检查我的xml文件,如果发现任何错误,请通知我。
我的MainActivity.java: -
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader = new ArrayList<String>();
HashMap<String, List<String>> listDataChild = new HashMap<String, List<String>>();;
List<String> innerhref = new ArrayList<>();
// private List<String> firstLevelSubMenus = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
// prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
textView = (TextView)findViewById(R.id.discount_and_offers);
view = findViewById(R.id.discount_and_offers_view);
textView1 = (TextView)findViewById(R.id.grad_offer_details);
linearLayout01 = (LinearLayout)findViewById(R.id.linear_layout_inner_image01);
linearLayoutDiscount01 = (LinearLayout)findViewById(R.id.linear_layout_inner_discount_image01);
linearLayoutmens =(LinearLayout)findViewById(R.id.line3);
linearLayoutMens01 = (LinearLayout)findViewById(R.id.linear_layout_inner_mens_image01);
linearLayoutMens02 = (LinearLayout)findViewById(R.id.linear_layout_inner_mens_name01);
linearLayoutMens03 = (LinearLayout)findViewById(R.id.linear_layout_inner_mens_price01);
mDemoSlider = (SliderLayout)findViewById(R.id.slider);
new Menus().execute("http://opencart.codeniques.com/shopping/?route=feed/web_api/menu&key=test123$");
new ImageSlider().execute("http://opencart.codeniques.com/shopping/?route=feed/web_api/slider&key=test123$");
new SpecialProduct().execute("http://opencart.codeniques.com/shopping/?route=feed/web_api/specialproduct&key=test123$");
new DiscountProduct().execute("http://opencart.codeniques.com/shopping/?route=feed/web_api/discountproduct&key=test123$");
new FrontCategories().execute("http://opencart.codeniques.com/shopping/?route=feed/web_api/getfrontcategories&key=test123$");
}
public class Menus extends AsyncTask<String,Void,Void>{
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(String... params) {
try{
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(params[0]);
HttpResponse response = client.execute(httpPost);
int status = response.getStatusLine().getStatusCode();
if(status==200){
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsonObject = new JSONObject(data);
JSONArray jsonArray = jsonObject.getJSONArray("categories");
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
listDataHeader.add(jsonObject1.getString("name"));
JSONArray jsonArray1 = jsonObject1.getJSONArray("children");
for(int j=0;j<jsonArray1.length();j++){
JSONObject jsonObject2 = jsonArray1.getJSONObject(j);
List<String> innerChild = new ArrayList<>();
innerChild.add(jsonObject2.getString("name"));
innerhref.add(jsonObject2.getString("href"));
listDataChild.put(listDataHeader.get(i),innerChild);
}
}
}
}catch (IOException |JSONException e){
Log.e("Error :",e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}
}
我的XMl: -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout_outer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ExpandableListView
android:id="@+id/lvExp"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start">
</ExpandableListView>
<ScrollView
android:id="@+id/list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/line3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</FrameLayout>
<com.daimajia.slider.library.SliderLayout
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="100dp" />
<!-- <View
android:id="@+id/grad_offer_details_view"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@android:color/darker_gray"/> -->
<TextView
android:id="@+id/grad_offer_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Grab Before Time Runs Out"
android:gravity="center"
android:textSize="20dp"/>
<View
android:id="@+id/yellow_draw_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#FF00FF00"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:id="@+id/linear_layout_outer_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout_inner_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:visibility="gone"/>
<TextView
android:id="@+id/text_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
<TextView
android:id="@+id/text__"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<View
android:id="@+id/discount_and_offers_view"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#d3d3d3"/>
<!-- android:background="@android:color/gray" -->
<TextView
android:id="@+id/discount_and_offers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Discount And Offers"
android:gravity="center"
android:textSize="20dp"/>
<View
android:id="@+id/green_draw_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#FF00FF00"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:id="@+id/linear_layout_outer_discount_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout_inner_discount_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/discount_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:visibility="gone"/>
<TextView
android:id="@+id/discount_text_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
<TextView
android:id="@+id/discount_text__"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#d3d3d3"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:visibility="gone">
<LinearLayout
android:id="@+id/linear_layout_outer_mans_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:id="@+id/linear_layout_inner_mens_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<ImageView
android:id="@+id/mens_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:visibility="gone"/>
<TextView
android:id="@+id/mens_text__"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
<TextView
android:id="@+id/mens_textPrice_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linear_layout_inner_mens_name01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/mens_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linear_layout_inner_mens_price01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/mens_textPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@android:color/darker_gray"/>
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
我的输出显示在图片下方: -
当我拖动抽屉布局显示在图像下方时: -
单击菜单列表后。
我也希望listview也打开点击应用程序名称..我是android开发中的新手帮助我!提前致谢
答案 0 :(得分:0)
尝试下面的xml,让我知道它是否有效
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout_outer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</LinearLayout>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/line3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</FrameLayout>
<com.daimajia.slider.library.SliderLayout
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="100dp" />
<!-- <View
android:id="@+id/grad_offer_details_view"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@android:color/darker_gray"/> -->
<TextView
android:id="@+id/grad_offer_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Grab Before Time Runs Out"
android:gravity="center"
android:textSize="20dp"/>
<View
android:id="@+id/yellow_draw_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#FF00FF00"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:id="@+id/linear_layout_outer_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout_inner_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:visibility="gone"/>
<TextView
android:id="@+id/text_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
<TextView
android:id="@+id/text__"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<View
android:id="@+id/discount_and_offers_view"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#d3d3d3"/>
<!-- android:background="@android:color/gray" -->
<TextView
android:id="@+id/discount_and_offers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Discount And Offers"
android:gravity="center"
android:textSize="20dp"/>
<View
android:id="@+id/green_draw_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#FF00FF00"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:id="@+id/linear_layout_outer_discount_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout_inner_discount_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/discount_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:visibility="gone"/>
<TextView
android:id="@+id/discount_text_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
<TextView
android:id="@+id/discount_text__"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#d3d3d3"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:visibility="gone">
<LinearLayout
android:id="@+id/linear_layout_outer_mans_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:id="@+id/linear_layout_inner_mens_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<ImageView
android:id="@+id/mens_image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:visibility="gone"/>
<TextView
android:id="@+id/mens_text__"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
<TextView
android:id="@+id/mens_textPrice_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linear_layout_inner_mens_name01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/mens_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linear_layout_inner_mens_price01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/mens_textPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@android:color/darker_gray"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
<ExpandableListView
android:id="@+id/lvExp"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start">
</ExpandableListView>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>