应用已停止(Jelly Bean 4.1.2)

时间:2013-12-02 14:34:19

标签: android android-4.2-jelly-bean

我正在使用“可搜索字典”示例代码。我在Eclipse上开发的每个应用程序在android 4.1.2中都不起作用(它总是停止应用程序),但在旧版本中工作得很好。

发生了什么事?这是我的代码:

我的logcat

12-02 11:45:40.012: W/ActivityThread(24344): Application com.pesquisa.dicionario.searchabledict can be debugged on port 8100...
12-02 11:45:40.102: I/ActivityThread(24344): Pub com.pesquisa.dicionario.searchabledict.DictionaryProvider: com.pesquisa.dicionario.searchabledict.DictionaryProvider
12-02 11:45:40.212: D/dalvikvm(24344): GC_FOR_ALLOC freed 85K, 9% free 9453K/10307K, paused 32ms, total 32ms
12-02 11:45:40.232: I/dalvikvm-heap(24344): Grow heap (frag case) to 15.354MB for 5738164-byte allocation
12-02 11:45:40.282: D/dalvikvm(24344): GC_CONCURRENT freed <1K, 6% free 15056K/15943K, paused 29ms+4ms, total 55ms
12-02 11:45:40.503: D/AbsListView(24344): Get MotionRecognitionManager
12-02 11:45:40.573: D/libEGL(24344): loaded /vendor/lib/egl/libGLES_vc4.so
 12-02 11:45:40.573: D/(24344): SpyHook inactive - could not find libspyhook.so [Symbol not found: ] or not enabled (debug.egl.hw.spy = 0)
12-02 11:45:40.593: W/khrn_client(24344): init_window num_buffers 3 min undequeued buffers 1 type 1
12-02 11:45:40.593: W/khrn_client(24344): init_window window 0x40f296d0, 480x800 hintTransform 0x0
12-02 11:45:40.623: D/OpenGLRenderer(24344): Enabling debug mode 0
12-02 11:45:44.356: D/AbsListView(24344): Get MotionRecognitionManager
12-02 11:45:44.436: W/khrn_client(24344): init_window num_buffers 3 min undequeued buffers 1 type 1
12-02 11:45:44.436: W/khrn_client(24344): init_window window 0x4d5da008, 399x84 hintTransform 0x0
12-02 11:45:45.377: W/InputEventReceiver(24344): Attempted to finish an input event but the input event receiver has already been disposed.
 12-02 11:45:46.639: W/khrn_client(24344): init_window num_buffers 3 min undequeued buffers 1 type 1
12-02 11:45:46.639: W/khrn_client(24344): init_window window 0x4d5da008, 399x84 hintTransform 0x0
12-02 11:45:47.329: D/GestureDetector(24344): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 4 mFalseSizeCnt:0
12-02 11:45:47.449: E/SensorManager(24344): thread start
12-02 11:45:47.459: D/SensorManager(24344): registerListener :: handle = 4  name= MPL accel delay= 200000  
 12-02 11:45:47.559: W/khrn_client(24344): init_window num_buffers 3 min undequeued buffers 1 type 1
 12-02 11:45:47.559: W/khrn_client(24344): init_window window 0x4d5da008, 480x762 hintTransform 0x0
   12-02 11:45:47.840: E/SpannableStringBuilder(24344): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
  12-02 11:45:47.840: E/SpannableStringBuilder(24344): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
  12-02 11:45:48.490: W/khrn_client(24344): init_window num_buffers 3 min undequeued buffers 1 type 1
  12-02 11:45:48.490: W/khrn_client(24344): init_window window 0x4d5da008, 480x368 hintTransform 0x0
  12-02 11:45:50.102: D/AbsListView(24344): Get MotionRecognitionManager
  12-02 11:45:50.172: W/khrn_client(24344): init_window num_buffers 3 min undequeued buffers 1 type 1
   12-02 11:45:50.172: W/khrn_client(24344): init_window window 0x4db44430, 461x304 hintTransform 0x0
  12-02 11:45:51.353: D/GestureDetector(24344): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 3 mFalseSizeCnt:0
  12-02 11:45:51.543: D/SensorManager(24344): unregisterListener::  
   12-02 11:45:51.543: D/Sensors(24344): Remain listener = Sending .. normal delay 200ms
  12-02 11:45:51.543: I/Sensors(24344): sendDelay --- 200000000
  12-02 11:45:51.543: D/SensorManager(24344): JNI - sendDelay
  12-02 11:45:51.543: I/SensorManager(24344): Set normal delay = true
  12-02 11:45:51.593: D/AbsListView(24344): Get MotionRecognitionManager
  12-02 11:45:51.633: W/khrn_client(24344): init_window num_buffers 3 min undequeued buffers 1 type 1
   12-02 11:45:51.633: W/khrn_client(24344): init_window window 0x4d619928, 480x800 hintTransform 0x0
   12-02 11:45:51.643: D/AndroidRuntime(24344): Shutting down VM
  12-02 11:45:51.643: W/dalvikvm(24344): threadid=1: thread exiting with uncaught exception (group=0x410f12a0)
   12-02 11:45:51.664: E/AndroidRuntime(24344): FATAL EXCEPTION: main
  12-02 11:45:51.664: E/AndroidRuntime(24344): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pesquisa.dicionario.searchabledict/com.pesquisa.dicionario.searchabledict.WordActivity}: java.lang.NullPointerException
   12-02 11:45:51.664: E/AndroidRuntime(24344):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at android.app.ActivityThread.access$700(ActivityThread.java:140)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at android.os.Handler.dispatchMessage(Handler.java:99)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at android.os.Looper.loop(Looper.java:137)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at android.app.ActivityThread.main(ActivityThread.java:4935)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at java.lang.reflect.Method.invokeNative(Native Method)
   12-02 11:45:51.664: E/AndroidRuntime(24344):     at java.lang.reflect.Method.invoke(Method.java:511)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
   12-02 11:45:51.664: E/AndroidRuntime(24344):     at dalvik.system.NativeStart.main(Native Method)
  12-02 11:45:51.664: E/AndroidRuntime(24344): Caused by: java.lang.NullPointerException
   12-02 11:45:51.664: E/AndroidRuntime(24344):     at com.pesquisa.dicionario.searchabledict.WordActivity.onCreate(WordActivity.java:30)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at android.app.Activity.performCreate(Activity.java:5206)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
  12-02 11:45:51.664: E/AndroidRuntime(24344):  ... 11 more

DictionaryDatabase.java

package com.pesquisa.dicionario.searchabledict;

import android.app.SearchManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.provider.BaseColumns;
 import android.text.TextUtils;
 import android.util.Log;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.HashMap;

 import com.pesquisa.dicionario.searchabledict.R;


public class DictionaryDatabase {
private static final String TAG = "DictionaryDatabase";

public static final String KEY_WORD = SearchManager.SUGGEST_COLUMN_TEXT_1;
public static final String KEY_DEFINITION = SearchManager.SUGGEST_COLUMN_TEXT_2;

private static final String DATABASE_NAME = "dictionary";
private static final String FTS_VIRTUAL_TABLE = "FTSdictionary";
private static final int DATABASE_VERSION = 2;

private final DictionaryOpenHelper mDatabaseOpenHelper;
private static final HashMap<String,String> mColumnMap = buildColumnMap();

public DictionaryDatabase(Context context) {
    mDatabaseOpenHelper = new DictionaryOpenHelper(context);
}

private static HashMap<String,String> buildColumnMap() {
    HashMap<String,String> map = new HashMap<String,String>();
    map.put(KEY_WORD, KEY_WORD);
    map.put(KEY_DEFINITION, KEY_DEFINITION);
    map.put(BaseColumns._ID, "rowid AS " +
            BaseColumns._ID);
    map.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID, "rowid AS " +
            SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
    map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS " +
            SearchManager.SUGGEST_COLUMN_SHORTCUT_ID);
    return map;
}

public Cursor getWord(String rowId, String[] columns) {
    String selection = "rowid = ?";
    String[] selectionArgs = new String[] {rowId};

    return query(selection, selectionArgs, columns);

}

public Cursor getWordMatches(String query, String[] columns) {
    String selection = KEY_WORD + " MATCH ?";
    String[] selectionArgs = new String[] {query+"*"};

    return query(selection, selectionArgs, columns);

}

private Cursor query(String selection, String[] selectionArgs, String[] columns) {

    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(FTS_VIRTUAL_TABLE);
    builder.setProjectionMap(mColumnMap);

    Cursor cursor = builder.query(mDatabaseOpenHelper.getReadableDatabase(),
            columns, selection, selectionArgs, null, null, null);

    if (cursor == null) {
        return null;
    } else if (!cursor.moveToFirst()) {
        cursor.close();
        return null;
    }
    return cursor;
}

private static class DictionaryOpenHelper extends SQLiteOpenHelper {

    private final Context mHelperContext;
    private SQLiteDatabase mDatabase;

    private static final String FTS_TABLE_CREATE =
                "CREATE VIRTUAL TABLE " + FTS_VIRTUAL_TABLE +
                " USING fts3 (" +
                KEY_WORD + ", " +
                KEY_DEFINITION + ");";

    DictionaryOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        mHelperContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        mDatabase = db;
        mDatabase.execSQL(FTS_TABLE_CREATE);
        loadDictionary();
    }

    private void loadDictionary() {
        new Thread(new Runnable() {
            public void run() {
                try {
                    loadWords();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }).start();
    }

    private void loadWords() throws IOException {
        Log.d(TAG, "Loading words...");
        final Resources resources = mHelperContext.getResources();
        InputStream inputStream = resources.openRawResource(R.raw.definitions);
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

        try {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] strings = TextUtils.split(line, "//");
                if (strings.length < 2) continue;
                long id = addWord(strings[0].trim(), strings[1].trim());
                if (id < 0) {
                    Log.e(TAG, "unable to add word: " + strings[0].trim());
                }
            }
        } finally {
            reader.close();
        }
        Log.d(TAG, "DONE loading words.");
    }


    public long addWord(String word, String definition) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_WORD, word);
        initialValues.put(KEY_DEFINITION, definition);

        return mDatabase.insert(FTS_VIRTUAL_TABLE, null, initialValues);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + FTS_VIRTUAL_TABLE);
        onCreate(db);
    }
}

}

DictionaryProvider.java

package com.pesquisa.dicionario.searchabledict;


import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;

public class DictionaryProvider extends ContentProvider {
String TAG = "DictionaryProvider";

public static String AUTHORITY = "com.pesquisa.dicionario.searchabledict.DictionaryProvider";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/dictionary");

public static final String WORDS_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE +
                                              "/vnd.pesquisa.dicionario.searchabledict";
public static final String DEFINITION_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE +
                                                   "/vnd.pesquisa.dicionario.searchabledict";

private DictionaryDatabase mDictionary;

private static final int SEARCH_WORDS = 0;
private static final int GET_WORD = 1;
private static final int SEARCH_SUGGEST = 2;
private static final int REFRESH_SHORTCUT = 3;
private static final UriMatcher sURIMatcher = buildUriMatcher();

private static UriMatcher buildUriMatcher() {
    UriMatcher matcher =  new UriMatcher(UriMatcher.NO_MATCH);
    matcher.addURI(AUTHORITY, "dictionary", SEARCH_WORDS);
    matcher.addURI(AUTHORITY, "dictionary/#", GET_WORD);
    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);

    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT, REFRESH_SHORTCUT);
    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", REFRESH_SHORTCUT);
    return matcher;
}

@Override
public boolean onCreate() {
    mDictionary = new DictionaryDatabase(getContext());
    return true;
}

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                    String sortOrder) {

    switch (sURIMatcher.match(uri)) {
        case SEARCH_SUGGEST:
            if (selectionArgs == null) {
              throw new IllegalArgumentException(
                  "selectionArgs must be provided for the Uri: " + uri);
            }
            return getSuggestions(selectionArgs[0]);
        case SEARCH_WORDS:
            if (selectionArgs == null) {
              throw new IllegalArgumentException(
                  "selectionArgs must be provided for the Uri: " + uri);
            }
            return search(selectionArgs[0]);
        case GET_WORD:
            return getWord(uri);
        case REFRESH_SHORTCUT:
            return refreshShortcut(uri);
        default:
            throw new IllegalArgumentException("Unknown Uri: " + uri);
    }
}

private Cursor getSuggestions(String query) {
  query = query.toLowerCase();
  String[] columns = new String[] {
      BaseColumns._ID,
      DictionaryDatabase.KEY_WORD,
      SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID};

  return mDictionary.getWordMatches(query, columns);
}

private Cursor search(String query) {
  query = query.toLowerCase();
  String[] columns = new String[] {
      BaseColumns._ID,
      DictionaryDatabase.KEY_WORD,
      DictionaryDatabase.KEY_DEFINITION};

  return mDictionary.getWordMatches(query, columns);
}

private Cursor getWord(Uri uri) {
  String rowId = uri.getLastPathSegment();
  String[] columns = new String[] {
      DictionaryDatabase.KEY_WORD,
      DictionaryDatabase.KEY_DEFINITION};

  return mDictionary.getWord(rowId, columns);
}

private Cursor refreshShortcut(Uri uri) {

  String rowId = uri.getLastPathSegment();
  String[] columns = new String[] {
      BaseColumns._ID,
      DictionaryDatabase.KEY_WORD,
      DictionaryDatabase.KEY_DEFINITION,
      SearchManager.SUGGEST_COLUMN_SHORTCUT_ID,
      SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID};

  return mDictionary.getWord(rowId, columns);
}

@Override
public String getType(Uri uri) {
    switch (sURIMatcher.match(uri)) {
        case SEARCH_WORDS:
            return WORDS_MIME_TYPE;
        case GET_WORD:
            return DEFINITION_MIME_TYPE;
        case SEARCH_SUGGEST:
            return SearchManager.SUGGEST_MIME_TYPE;
        case REFRESH_SHORTCUT:
            return SearchManager.SHORTCUT_MIME_TYPE;
        default:
            throw new IllegalArgumentException("Unknown URL " + uri);
    }
}

@Override
public Uri insert(Uri uri, ContentValues values) {
    throw new UnsupportedOperationException();
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    throw new UnsupportedOperationException();
}

@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    throw new UnsupportedOperationException();
}

}

SenseDictionary.java

public class SenseDictionary extends Activity {

private TextView mTextView;
private ListView mListView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);

    mTextView = (TextView) findViewById(R.id.text);
    mListView = (ListView) findViewById(R.id.list);

    handleIntent(getIntent());
}

@Override
protected void onNewIntent(Intent intent) {
    handleIntent(intent);
}

private void handleIntent(Intent intent) {
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Intent wordIntent = new Intent(this, WordActivity.class);
        wordIntent.setData(intent.getData());
        startActivity(wordIntent);
    } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        showResults(query);
    }
}

private void showResults(String query) {

    Cursor cursor = managedQuery(DictionaryProvider.CONTENT_URI, null, null,
                            new String[] {query}, null);

    if (cursor == null) {
        mTextView.setText(getString(R.string.no_results, new Object[] {query}));
    } else {
        int count = cursor.getCount();
        String countString = getResources().getQuantityString(R.plurals.search_results,
                                count, new Object[] {count, query});
        mTextView.setText(countString);

        String[] from = new String[] { DictionaryDatabase.KEY_WORD,
                                       DictionaryDatabase.KEY_DEFINITION };

        int[] to = new int[] { R.id.word,
                               R.id.definition };

        SimpleCursorAdapter words = new SimpleCursorAdapter(this,
                                      R.layout.result, cursor, from, to);
        mListView.setAdapter(words);

        mListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent wordIntent = new Intent(getApplicationContext(), WordActivity.class);
                Uri data = Uri.withAppendedPath(DictionaryProvider.CONTENT_URI,
                                                String.valueOf(id));
                wordIntent.setData(data);
                startActivity(wordIntent);
            }
        });
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.search:
            onSearchRequested();
            return true;
        default:
            return false;
    }
}

}

WordActivity.java

package com.pesquisa.dicionario.searchabledict;



import com.pesquisa.dicionario.searchabledict.R;

 import android.app.Activity;
 import android.app.ActionBar;
 import android.app.SearchManager;
 import android.content.Context;
 import android.content.Intent;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.widget.SearchView;
 import android.widget.TextView;

public class WordActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.word);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    Uri uri = getIntent().getData();
    Cursor cursor = managedQuery(uri, null, null, null, null);

    if (cursor == null) {
        finish();
    } else {
        cursor.moveToFirst();

        TextView word = (TextView) findViewById(R.id.word);
        TextView definition = (TextView) findViewById(R.id.definition);

        int wIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_WORD);
        int dIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_DEFINITION);

        word.setText(cursor.getString(wIndex));
        definition.setText(cursor.getString(dIndex));
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.search:
            onSearchRequested();
            return true;
        case android.R.id.home:
            Intent intent = new Intent(this, SenseDictionary.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            return true;
        default:
            return false;
    }
}
}

LAYOUTS

main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/intro">

 <TextView
     android:id="@+id/text"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:background="@drawable/fundo"
     android:gravity="center"
     android:text="@string/search_instructions"
     android:textColor="?android:textColorPrimary"
     android:textSize="17sp" />

<ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

为result.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp"
    android:background="#ffffff">
<TextView
        android:id="@+id/word"
        style="@android:style/TextAppearance.Large"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:background="#ffffff"/>

word.xml

<?xml version="1.0" encoding="utf-8"?>

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
  android:layout_height="match_parent"
 android:orientation="vertical">

  <LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">
    <TextView
        android:id="@+id/word"
        android:textSize="35dp"
        android:textColor="?android:textColorPrimary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
    android:id="@+id/definition"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="10dp"
    android:textColor="#ff0000"
    android:textSize="18dp" />



   </LinearLayout>

   </ScrollView>

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pesquisa.dicionario.searchabledict"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/icon2"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.pesquisa.dicionario.searchabledict.SenseDictionary"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>

        <meta-data android:name="android.app.searchable"
                   android:resource="@xml/searchable" />

    </activity>

    <activity android:name="com.pesquisa.dicionario.searchabledict.WordActivity" />

    <provider android:name="com.pesquisa.dicionario.searchabledict.DictionaryProvider"
              android:authorities="com.pesquisa.dicionario.searchabledict.DictionaryProvider" />

    <meta-data android:name="android.app.default_searchable"
               android:value=".SenseDictionary" />


</application>

0 个答案:

没有答案