简体   繁体   English

应用程序未在真实设备上显示listview,但可在模拟器上运行

[英]app not showing listview on real device but works on emulator

Our question is about a listview that uses a recyclerview and is interfaced with a RecyclerAdapter. 我们的问题是关于一个使用recyclerview并与RecyclerAdapter接口的列表视图。 The ListView will show the data on both the device and emulator. ListView将在设备和仿真器上显示数据。 The problem is with the device Samsung SM-T810 with Android 7 APK 24 installed the ListView shows once but if you close the app and restart the ListView no longer show. 问题出在安装了Android 7 APK 24的设备Samsung SM-T810上,ListView会显示一次,但是如果您关闭应用程序并重新启动ListView,则不再显示。 On the emulator Nexus 5X target & compile SDK 27 min SDK 19 if you close the app and restart the ListView is reloaded and shows data just fine 在模拟器Nexus 5X目标上并编译SDK 27分钟SDK 19如果关闭应用程序并重新启动,则ListView将重新加载并显示数据
So the question is this an issue with the code or with the REAL device ? 那么问题是代码或REAL设备有问题吗? We have checked with DBBrowser and the information is in the listview data is in the appropriate table 我们已经与DBBrowser进行了检查,该信息在listview中,数据在适当的表中
We will post the code below 我们将在下面发布代码

public class TableListView extends AppCompatActivity {

DBHelper dbHelper = new DBHelper(this);

RecyclerView mRecyclerView;
private static RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;

LinearLayout firstLL;
LinearLayout mainLL;
TextView tvNoData;

static final int READ_BLOCK_SIZE = 100;
static String stringREAD;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_table_list_view);

    setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    firstLL = findViewById(R.id.firstLL);
    mainLL = findViewById(R.id.mainLL);
    tvNoData = findViewById(R.id.tvNoData);

    readFROM_TEXT_FILE();

    dbHelper = new DBHelper(this);
    List<TableModel> dbTTList;
    dbTTList = dbHelper.getDataFrom_TABLE_TRACKER();

    int sz = dbTTList.size();

    if(stringREAD.equals("EXTERNAL") || stringREAD.equals("INTERNAL") && sz == 0){
        System.out.println("################ SIZE top "+sz);

        tvNoData.setVisibility(View.VISIBLE);
        tvNoData.setText("No Data Found\n\nClick On Manage Tables");

        mRecyclerView = findViewById(R.id.recycleview);
        mRecyclerView.setHasFixedSize(true);

        mLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLayoutManager);

        mAdapter = new TableTrackerAdapter(this,dbTTList);
        mRecyclerView.setAdapter(mAdapter);
    }
    if(stringREAD.equals("EXTERNAL") || stringREAD.equals("INTERNAL") && sz > 0){
        System.out.println("################ SIZE bot "+sz);
        mRecyclerView = findViewById(R.id.recycleview);
        mRecyclerView.setHasFixedSize(true);

        mLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLayoutManager);

        mAdapter = new TableTrackerAdapter(this,dbTTList);
        mRecyclerView.setAdapter(mAdapter);

        tvNoData.setVisibility(View.INVISIBLE);

    }

    setTitle("");// This sets the title of the toolbar
    Toolbar topToolBar = findViewById(R.id.toolbar);
    setSupportActionBar(topToolBar);
    addListenerOnButtonAdd();

    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {

        } else {
            requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 666);  // Comment 26
        }
    }

}// END onCreate

This took some digging into one of your old posts where Comonsware and you were talking about EXTERNAL and INTERNAL storage here is a link here I plugged this code in and made it the launch activity. 这深入研究了您的其中一篇老文章,其中Comonsware和您正在谈论EXTERNAL和INTERNAL存储,这里是一个链接我在其中插入了此代码并将其作为启动活动。 With a few tweaks we forced this code to re-establish your THE_PATH for some reason this code with out the tweaks was changing the the THE_PATH to INTERNAL storage that was why your data was lost the app was looking for what had been stored EXTERNAL with a INTERNAL path here is the tweaked code from the launcher activity 进行了一些调整,出于某种原因,我们强制该代码重新建立了THE_PATH,而没有进行任何调整,却将THE_PATH更改为INTERNAL存储,这就是为什么您的数据丢失的原因,该应用正在寻找使用EXTERNAL存储的内容内部路径是启动器活动中经过调整的代码

    public void chkHere(){

    if(stringREAD.equals("EXTERNAL") || stringREAD.equals("INTERNAL")){
        onNEXT(null);
        System.out.println("******************** I WAS FIRED"+THE_PATH);

        Intent intent = new Intent(CheckStorageActivity.this, TableListView.class);
        startActivity(intent);
    }
}

public void onNEXT(View view){

    File fi = new File("storage/");
    File[] lst = fi.listFiles();
    String top = String.valueOf(lst[1]);
    String bot = String.valueOf(lst[0]);
    System.out.println("###################################### top 1 "+top);
    System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ bot 0 "+bot);

    if(bot.contains("-")){
        STORAGE_LOCATION = 1;
    }
    if(top.contains("storage/enc_emulated")){
        STORAGE_LOCATION = 0;
    }

    if(stringREAD.matches("EMPTY") && STORAGE_LOCATION == 1){
        storageDIALOG();
    }
    if(stringREAD.matches("EMPTY") && STORAGE_LOCATION == 0) {
        internalDIALOG();
    }

    // This Code Below Maintains the variable THE_PATH
    if(stringREAD.matches("EXTERNAL")) {
        STORAGE_LOCATION = 1;
        getThePath();
    }
    if(stringREAD.matches("INTERNAL")){
        STORAGE_LOCATION = 0;
        getThePath();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM