Java 该输入未显示在ListView上

Java 该输入未显示在ListView上,java,android,database,android-layout,listview,Java,Android,Database,Android Layout,Listview,我遵循了这个指示 通常,在我输入一个字符串(标记)后,它应该显示在Listview上,但我会一直看到在我创建的数据库中没有数据时显示的字符串 MainActivity.java package ch.ethz.twimight.activities; import android.app.ListActivity; import android.os.Bundle; import ch.ethz.twimight.R; import ch.ethz.twimight.net.twitter.T

我遵循了这个指示

通常,在我输入一个字符串(标记)后,它应该显示在Listview上,但我会一直看到在我创建的数据库中没有数据时显示的字符串

MainActivity.java

package ch.ethz.twimight.activities;

import android.app.ListActivity;
import android.os.Bundle;
import ch.ethz.twimight.R;
import ch.ethz.twimight.net.twitter.Tags;
import android.app.LoaderManager;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class MytagsActivity extends ListActivity implements
LoaderManager.LoaderCallbacks<Cursor> {

  private static final int ACTIVITY_CREATE = 0;
  private static final int DELETE_ID = Menu.FIRST + 1;

  private SimpleCursorAdapter adapter;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mytags);
    this.getListView().setDividerHeight(2);
    fillData();
    registerForContextMenu(getListView());


  }

@Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.my_tags, menu);
    return true;
  }

@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.Add:

      createTodo();
      return true;
    }
    return super.onOptionsItemSelected(item);
  }


@Override
  public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case DELETE_ID:
      AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
          .getMenuInfo();
      Uri uri = Uri.parse(Tags.CONTENT_URI + "/"
          + info.id);
      getContentResolver().delete(uri, null, null);
      //fillData();
      return true;
    }
    return super.onContextItemSelected(item);
  }

private void createTodo() {
    Intent i = new Intent(this, MyTagsActivity_D.class);
    startActivity(i);
  }

private void fillData() {

    // Fields from the database (projection)
    // Must include the _id column for the adapter to work
    String[] from = new String[] { Tags.COL_TEXT };
    // Fields on the UI to which we map
    int[] to = new int[] { R.id.label };

    //getLoaderManager().initLoader(0, null, this);
    ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.mytags_row, null, from,
        to, 0);

    setListAdapter(adapter);
  }


@Override
  public void onCreateContextMenu(ContextMenu menu, View v,
      ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.add(0, DELETE_ID, 0, R.string.delete_tag);
  }



@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // TODO Auto-generated method stub
    String[] projection = { Tags.COL_ROW_ID, Tags.COL_TEXT};
    CursorLoader cursorLoader = new CursorLoader(this,
        Tags.CONTENT_URI, projection, null, null, null);
    return cursorLoader;
}

@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor data) {
    // TODO Auto-generated method stub
    adapter.swapCursor(data);

}

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        // TODO Auto-generated method stub
        adapter.swapCursor(null);

    }

}
我一定错过了什么…我在这里呆了两天

我检查了其他示例代码,但仍然无法找出我遗漏了什么


请帮助,谢谢。

您在LogCat中看到了什么吗?是的,但它没有显示任何错误消息,我向LogCat提出了问题,但我根本不理解这些消息:(
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

    <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_tags" />

</LinearLayout> 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="30dp"
        android:layout_height="24dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:src="@drawable/ic_tag" >
    </ImageView>

    <TextView
        android:id="@+id/label"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:lines="1"
        android:text="@+id/TextView01"
        android:textSize="24sp" >
    </TextView>

</LinearLayout> 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >



        <LinearLayout
            android:id="@+id/LinearLayout01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <EditText
                android:id="@+id/addtag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="@string/new_tag"
                android:imeOptions="actionNext" >
            </EditText>
        </LinearLayout>



        <Button
            android:id="@+id/ilikeit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ilikeit" >
        </Button>


    </LinearLayout> 
package ch.ethz.twimight.net.twitter;

import java.util.Arrays;
import java.util.HashSet;

import ch.ethz.twimight.data.DBOpenHelper;
import android.content.ContentProvider;
import android.content.ContentValues;
//import android.content.Intent;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

public class TagsContentProvider extends ContentProvider{

    private static final String TAG = TagsContentProvider.class.getSimpleName();

    private SQLiteDatabase database;
    private DBOpenHelper dbHelper;

    private static final UriMatcher tagsUriMatcher;

    private static final int TAGS = 1;
    private static final int TAGS_ID = 2;


    static {
        tagsUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        tagsUriMatcher.addURI(Tags.TAG_AUTHORITY, Tags.TAGS, TAGS);

        tagsUriMatcher.addURI(Tags.TAG_AUTHORITY, Tags.TAGS + "/#", TAGS_ID);


    @Override
    public synchronized int delete(Uri uri, String arg1, String[] arg2) {
        if (tagsUriMatcher.match(uri) != TAGS_ID)
            throw new IllegalArgumentException("Unsupported URI: " + uri);

        Log.d(TAG, "Delete TAGS_ID");

        int nrRows = database.delete(DBOpenHelper.TABLE_TAGS, "_id=" + uri.getLastPathSegment(), null);
        getContext().getContentResolver().notifyChange(Tags.CONTENT_URI, null);
        return nrRows;
    }

    @Override
    public String getType(Uri uri) {
        switch (tagsUriMatcher.match(uri)) {
        case TAGS:
            return Tags.TAGS_CONTENT_TYPE;
        case TAGS_ID:
            return Tags.TAG_CONTENT_TYPE;
        default:
            throw new IllegalArgumentException("Unknown URI: " + uri);
        }
    }

    private void checkColumns(String[] projection) {
        String[] available = {DBOpenHelper.COL_ROW_ID };
        if (projection != null) {
          HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection));
          HashSet<String> availableColumns = new HashSet<String>(Arrays.asList(available));
          // check if all columns which are requested are available
          if (!availableColumns.containsAll(requestedColumns)) {
            throw new IllegalArgumentException("Unknown columns in projection");
          }
        }
      }


    @Override
    public synchronized Uri insert(Uri uri, ContentValues values) {
        //int uriType = tagsUriMatcher.match(uri);
       // SQLiteDatabase sqlDB = database.getWritableDatabase();
        //int rowsDeleted = 0;
        long id = 0;
        switch (tagsUriMatcher.match(uri)) {
        case TAGS:
          id = database.insert(DBOpenHelper.TABLE_TAGS, null, values);
          break;
        default:
          throw new IllegalArgumentException("Unknown URI: " + uri);
        }
        getContext().getContentResolver().notifyChange(uri, null);
        return Uri.parse(Tags.TAGS + "/" + id);
    }

    @Override
    public boolean onCreate() {
        dbHelper = DBOpenHelper.getInstance(getContext().getApplicationContext());
        database = dbHelper.getWritableDatabase();
        return true;
    }

    @Override
    public synchronized Cursor query(Uri uri, String[] projection, String where, String[] whereArgs, String sortOrder) {
        if (TextUtils.isEmpty(sortOrder))
            sortOrder = Tags.DEFAULT_SORT_ORDER;

        checkColumns(projection);

        Cursor c = null;
        String sql = null;
        //Intent i = null;
        switch (tagsUriMatcher.match(uri)) {

        case TAGS:
            Log.d(TAG, "Query TAGS");
            c = database.query(DBOpenHelper.TABLE_TAGS, projection, where, whereArgs, null, null, sortOrder);
            c.setNotificationUri(getContext().getContentResolver(), Tags.CONTENT_URI);
            break;

        case TAGS_ID:
            Log.d(TAG, "Query TAGS_ID");
            sql = "SELECT  * " + "FROM " + DBOpenHelper.TABLE_TAGS + " " + "WHERE " + DBOpenHelper.TABLE_TAGS + "._id="
                    + uri.getLastPathSegment() + ";";
            c = database.rawQuery(sql, null);
            c.setNotificationUri(getContext().getContentResolver(), uri);
            break;

        default:
            throw new IllegalArgumentException("Unsupported URI: " + uri);
        }

        return c;
    }

    @Override
    public synchronized int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        int nrRows = database.update(DBOpenHelper.TABLE_TAGS, values, "_id=" + uri.getLastPathSegment(), null);
        switch (tagsUriMatcher.match(uri)){
        case TAGS:
            nrRows = database.update(DBOpenHelper.TABLE_TAGS, 
                  values, 
                  selection,
                  selectionArgs);
              break;
            case TAGS_ID:
              String id = uri.getLastPathSegment();
              if (TextUtils.isEmpty(selection)) {
                  nrRows = database.update(DBOpenHelper.TABLE_TAGS, 
                    values,
                    DBOpenHelper.COL_ROW_ID + "=" + id, 
                    null);
              } else {
                  nrRows = database.update(DBOpenHelper.TABLE_TAGS, 
                    values,
                    DBOpenHelper.COL_ROW_ID + "=" + id 
                    + " and " 
                    + selection,
                    selectionArgs);
              }
              break;
            default:
              throw new IllegalArgumentException("Unknown URI: " + uri);
            }
            getContext().getContentResolver().notifyChange(uri, null);
            return nrRows;

    }

}
W/ResourceType(10480): Skipping entry 0x1060072 in package table 0 because it is not complex!

D/TextView(10480): Constructor - Got appearance for textColorPrimaryInverse

D/TextView(10480): Constructor -- Got mEditTextBackgroundColor

W/IInputConnectionWrapper(10480): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(10480): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(10480): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(10480): endBatchEdit on inactive InputConnection