나는 ExpandedList를 가지고 있으며, 아이를 클릭하면 새로운 의도가 시작됩니다. 그러나 클릭 후 프로그램이 중단됩니다. 들여 쓰기를 실행하려면 standart 코드를 사용하는 것 같습니다. 내가 뭘 잘못하고있어? 내가 실행하려면 들여 쓰기오류로 새 들여 쓰기 시작
package com.test;
import android.app.ExpandableListActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.TextView;
public class OWActivity extends ExpandableListActivity {
ExpandableListAdapter mAdapter;
public String[] groups;
public String[][] children;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
Resources res = getResources();
groups = res.getStringArray(R.array.books_array);
String[] children_tmp = res.getStringArray(R.array.pray_array);
children = new String[children_tmp.length][];
for (int i = 0; i < children_tmp.length; i++) {
String[] separated = children_tmp[i].split(";");
children[i] = new String[separated.length];
for (int j = 0; j < separated.length; j++) {
children[i][j] = separated[j].trim();
}
}
} catch (Exception e) {
System.out.println("Errrr +++ " + e.getMessage());
}
// Set up our adapter
mAdapter = new MyExpandableListAdapter();
setListAdapter(mAdapter);
registerForContextMenu(getExpandableListView());
}
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for
// groups[i].
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
TextView textView = new TextView(OWActivity.this);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition, childPosition).toString());
textView.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// !!!!!!!!!!!!!!!!!!!!!!!!!!
// after this line - crash !!
// !!!!!!!!!!!!!!!!!!!!!!!!!!
Intent myIntent = new Intent(view.getContext(), ViewText.class);
startActivityForResult(myIntent, 0);
}
});
return textView;
}
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
public int getGroupCount() {
return groups.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}
}
클래스 : 여기 내 코드입니다. 나는 웹보기에 텍스트를로드 할 :
package com.test;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class ViewText extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_text);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("file:///android_asset/test.html");
};
}
ViewText.xml 레이아웃 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</WebView>
</LinearLayout>
logcat 로그를 추가하십시오. 또한 매니페스트에'ViewText'가 있습니까? – MByD
들여 쓰기가 아닌 인 텐트라고합니다. – Egor
AndroidManifest.xml에 ViewText가 선언되어 있습니까? – Ognyan