我不知道为什么我无法编译我的代码,它设置了我 ContentProvider.createUri 无法解析方法。我所缺少的任何人都可以告诉我。这是我的类代码:
public class Connectivity extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {
MySQLiteHelper db;
String[] name;
String[] username;
String[] password;
String[] category;
int[] ids;
int[] color;
ListView listView;
Cursor identityCursor;
FloatingActionButton addIndentity;
int REQUEST_CODE =0;
int color1;
ToastersAdapter customAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View android = inflater.inflate(R.layout.cards_frag, container, false);
addIndentity = (FloatingActionButton) android.findViewById(R.id.fab3);
db = new MySQLiteHelper(getActivity());
final List<IdentityHelper> list = db.getAllIdentities();
name= new String[db.getIdentitiesCount()];
username = new String[db.getIdentitiesCount()];
password = new String[db.getIdentitiesCount()];
category = new String[db.getIdentitiesCount()];
color = new int[db.getIdentitiesCount()];
ids = new int[db.getIdentitiesCount()];
for (int i = 0; i < list.size(); i++) {
IdentityHelper n= list.get(i);
name[i]= n.getName();
username[i]=n.getUsername();
password[i]=n.getPassword();
category[i]=n.getCategory();
color[i] = n.getColor();
ids[i] = n.getId();
}
addIndentity.setOnClickListener(handler);
// Get access to the underlying writeable database
SQLiteDatabase dbs = db.getWritableDatabase();
// Query for items from the database and get a cursor back
identityCursor = dbs.rawQuery("SELECT * FROM Identities ORDER BY category", null);
listView = (ListView) android.findViewById(R.id.listView1);
customAdapter = new ToastersAdapter(getActivity(), identityCursor);
listView.setAdapter(customAdapter);
addIndentity.attachToListView(listView);
getActivity().getSupportLoaderManager().initLoader(0, null, Connectivity.this);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapter, View v, int position,
long arg3)
{
ToastersAdapter adapter1 = (ToastersAdapter) adapter.getAdapter();
Object sectionObject = adapter1.getItem(position);
int cursorPosition = adapter1.getCursorPositionWithoutSections(position);
if (adapter1.isSection(position) && sectionObject != null) {
// Handle the section being clicked on.
Toast.makeText(getActivity(),"Header Clicked", Toast.LENGTH_SHORT).show();
} else if (cursorPosition != SectionCursorAdapter.NO_CURSOR_POSITION) {
// Handle the cursor item being clicked on.
//Create the bundle
Bundle bundle = new Bundle();
//Add your data from getFactualResults method to bundle
bundle.putString("Name", name[cursorPosition]);
bundle.putString("Username",username[cursorPosition]);
bundle.putString("Password",password[cursorPosition]);
bundle.putString("Category", category[cursorPosition]);
bundle.putInt("Color", color[cursorPosition]);
bundle.putInt("ID", ids[cursorPosition]);
Intent intent = new Intent(getActivity(), theIdentity.class);
intent.putExtras(bundle);
Connectivity.this.startActivity(intent);
getActivity().overridePendingTransition(R.anim.slide_in_top, R.anim.slide_out_top);
getActivity().finish();
}}
});
return android;
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
**String orderBy = category[id] + " ASC, " + name[id] + " ASC";
return new CursorLoader(this, ContentProvider.createUri(IdentityHelper.class, null), null, null, null, orderBy);**
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
customAdapter.swapCursor(data);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
customAdapter.swapCursor(null);
}
我用过https://github.com/twotoasters/SectionCursorAdapter ,用于 Cursor 适配器来操作 ListView。我将非常感谢任何帮助
最佳答案
因为 android.content.ContentProvider 中没有 createUri
方法类,在我看来,您的 ContentProvider
类来自其他一些库。
可能是ActiveAndroid ,它在 com.activeandroid.content.ContentProvider
类中有 createUri
方法。
关于java - ContentProvider.createUri 无法解析方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30036052/