我对应用程序开发很新,我在第二个活动和三层之间移动时遇到错误的应用程序意外停止。两者的代码如下:
SecondAcivity
package com.example.expandinglists;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
public class SecondActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove TitleBar
requestWindowFeature(Window.FEATURE_NO_TITLE);
//The line below sets the convas / area labelled as activity_main
setContentView(R.layout.activity_second);
// Remove notification bar.
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//Declaring Button
setupNavigationButton();
}
//button class
private void setupNavigationButton() {
Button button = (Button) findViewById(R.id.btnOnSecond);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//The code below displays text when the button is pressed
//Toast.makeText(SecondActivity.this,"You Clicked it on 2nd Activity",Toast.LENGTH_LONG).show();
startActivity(new Intent(SecondActivity.this, threelayer.class));
//finish();
}
});
}
//End of button class
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
threelayer
package com.androidhub4you.multilevellistview;
import java.util.ArrayList;
import com.androidhub4you.multilevellistview.Product.SubCategory;
import com.androidhub4you.multilevellistview.Product.SubCategory.ItemList;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class threelayer extends Activity {
private ArrayList<Product>pProductArrayList;
private ArrayList<SubCategory>pSubItemArrayList;
private ArrayList<SubCategory>pSubItemArrayList2;
private LinearLayout mLinearListView;
boolean isFirstViewClick=false;
boolean isSecondViewClick=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_threelayer);
mLinearListView = (LinearLayout) findViewById(R.id.linear_listview);
/**
*
*/
ArrayList<ItemList> mItemListArray=new ArrayList<ItemList>();
mItemListArray.add(new ItemList("Red", "20"));
mItemListArray.add(new ItemList("Blue", "50"));
mItemListArray.add(new ItemList("Red", "20"));
mItemListArray.add(new ItemList("Blue", "50"));
ArrayList<ItemList> mItemListArray2=new ArrayList<ItemList>();
mItemListArray2.add(new ItemList("Pant", "2000"));
mItemListArray2.add(new ItemList("Shirt", "1000"));
mItemListArray2.add(new ItemList("Pant", "2000"));
mItemListArray2.add(new ItemList("Shirt", "1000"));
mItemListArray2.add(new ItemList("Pant", "2000"));
mItemListArray2.add(new ItemList("Shirt", "1000"));
/**
*
*/
pSubItemArrayList=new ArrayList<SubCategory>();
pSubItemArrayList2=new ArrayList<SubCategory>();
pSubItemArrayList.add(new SubCategory("Color", mItemListArray));
pSubItemArrayList2.add(new SubCategory("Cloths", mItemListArray2));
pSubItemArrayList.add(new SubCategory("Color", mItemListArray));
pSubItemArrayList2.add(new SubCategory("Cloths", mItemListArray2));
/**
*
*/
pProductArrayList=new ArrayList<Product>();
pProductArrayList.add(new Product("Emotions", pSubItemArrayList));
pProductArrayList.add(new Product("Garments", pSubItemArrayList2));
/***
* adding item into listview
*/
for (int i = 0; i < pProductArrayList.size(); i++) {
LayoutInflater inflater = null;
inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mLinearView = inflater.inflate(R.layout.row_first, null);
final TextView mProductName = (TextView) mLinearView.findViewById(R.id.textViewName);
final RelativeLayout mLinearFirstArrow=(RelativeLayout)mLinearView.findViewById(R.id.linearFirst);
final ImageView mImageArrowFirst=(ImageView)mLinearView.findViewById(R.id.imageFirstArrow);
final LinearLayout mLinearScrollSecond=(LinearLayout)mLinearView.findViewById(R.id.linear_scroll);
if(isFirstViewClick==false){
mLinearScrollSecond.setVisibility(View.GONE);
mImageArrowFirst.setBackgroundResource(R.drawable.arw_lt);
}
else{
mLinearScrollSecond.setVisibility(View.VISIBLE);
mImageArrowFirst.setBackgroundResource(R.drawable.arw_down);
}
mLinearFirstArrow.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(isFirstViewClick==false){
isFirstViewClick=true;
mImageArrowFirst.setBackgroundResource(R.drawable.arw_down);
mLinearScrollSecond.setVisibility(View.VISIBLE);
}else{
isFirstViewClick=false;
mImageArrowFirst.setBackgroundResource(R.drawable.arw_lt);
mLinearScrollSecond.setVisibility(View.GONE);
}
return false;
}
});
final String name = pProductArrayList.get(i).getpName();
mProductName.setText(name);
/**
*
*/
for (int j = 0; j < pProductArrayList.get(i).getmSubCategoryList().size(); j++) {
LayoutInflater inflater2 = null;
inflater2 = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mLinearView2 = inflater2.inflate(R.layout.row_second, null);
TextView mSubItemName = (TextView) mLinearView2.findViewById(R.id.textViewTitle);
final RelativeLayout mLinearSecondArrow=(RelativeLayout)mLinearView2.findViewById(R.id.linearSecond);
final ImageView mImageArrowSecond=(ImageView)mLinearView2.findViewById(R.id.imageSecondArrow);
final LinearLayout mLinearScrollThird=(LinearLayout)mLinearView2.findViewById(R.id.linear_scroll_third);
if(isSecondViewClick==false){
mLinearScrollThird.setVisibility(View.GONE);
mImageArrowSecond.setBackgroundResource(R.drawable.arw_lt);
}
else{
mLinearScrollThird.setVisibility(View.VISIBLE);
mImageArrowSecond.setBackgroundResource(R.drawable.arw_down);
}
mLinearSecondArrow.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(isSecondViewClick==false){
isSecondViewClick=true;
mImageArrowSecond.setBackgroundResource(R.drawable.arw_down);
mLinearScrollThird.setVisibility(View.VISIBLE);
}else{
isSecondViewClick=false;
mImageArrowSecond.setBackgroundResource(R.drawable.arw_lt);
mLinearScrollThird.setVisibility(View.GONE);
}
return false;
}
});
final String catName = pProductArrayList.get(i).getmSubCategoryList().get(j).getpSubCatName();
mSubItemName.setText(catName);
/**
*
*/
for (int k = 0; k < pProductArrayList.get(i).getmSubCategoryList().get(j).getmItemListArray().size(); k++) {
LayoutInflater inflater3 = null;
inflater3 = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mLinearView3 = inflater3.inflate(R.layout.row_third, null);
TextView mItemName = (TextView) mLinearView3.findViewById(R.id.textViewItemName);
TextView mItemPrice = (TextView) mLinearView3.findViewById(R.id.textViewItemPrice);
final String itemName = pProductArrayList.get(i).getmSubCategoryList().get(j).getmItemListArray().get(k).getItemName();
final String itemPrice = pProductArrayList.get(i).getmSubCategoryList().get(j).getmItemListArray().get(k).getItemPrice();
mItemName.setText(itemName);
mItemPrice.setText(itemPrice);
mLinearScrollThird.addView(mLinearView3);
}
mLinearScrollSecond.addView(mLinearView2);
}
mLinearListView.addView(mLinearView);
}
}
}
这可能是次要的。
非常感谢帮助。
提前致谢,
Ĵ
答案 0 :(得分:0)
在我的情况下,这是android清单文件的问题。如果您是初学者并在遇到导致应用程序意外停止的错误时尝试预设代码,请确保清单文件按预期配置。