English 中文(简体)
安德列斯:有从档案中进口并转自Sting的阵列
原标题:Android: Trouble with array that s imported from a file and converted from String
  • 时间:2010-11-10 16:14:09
  •  标签:
  • android

我有一份案文文件,我正在从我的SD卡中取出,该卡片载有一阵式便衣。 这里是该档案的内容......

http://www.oddree.com/rayhaque/android1.jpg,http://www.oddree.com/rayhaque/android2.jpg,http://www.oddree.com/rayhaque/android3.jpg,http://www.oddree.com/rayhaque/android4.jpg,http://www.oddree.com/rayhaque/android5.jpg

我正试图将这一案文输入一个强硬体,将它变成一个阵列,然后把该阵列装成一个名单改编器。 如果我试图把读写成或读写成一个微不足道的结果,我就会被迫随时关闭。 如果我把档案内容抄录为“长处”,然后使用......一切照旧。

因此,从文字档案中装载这种 st子与从包括舱面上加载两者之间有何区别? 它是一成不变的问题吗?

这里是我的法典。 我注意到了什么是行之有效的,什么是失败的。

public class MainActivity extends Activity {

ListView list;
LazyAdapter adapter;
List<String> strings = new ArrayList<String>();
String readString = new String();
String arrayNBOW;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    try{
     File f = new File(Environment.getExternalStorageDirectory()+"/LazyList/gkindex.txt");
     FileInputStream fileIS = new FileInputStream(f);
     BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));

     while((readString = buf.readLine())!= null){
      String arrayNBOW = readString.trim();
      Toast.makeText(MainActivity.this, "STARTUPPULL: "+arrayNBOW, Toast.LENGTH_LONG).show();
     }
  } catch (FileNotFoundException e) {
   Toast.makeText(MainActivity.this, "FAIL: "+e, Toast.LENGTH_LONG).show();
   e.printStackTrace();
  } catch (IOException e){
   Toast.makeText(MainActivity.this, "FAIL: "+e, Toast.LENGTH_LONG).show();
   e.printStackTrace();
  }

    setContentView(R.layout.main);
    list=(ListView)findViewById(R.id.list);

    String testArray = "http://www.oddree.com/rayhaque/android1.jpg,http://www.oddree.com/rayhaque/android2.jpg,http://www.oddree.com/rayhaque/android3.jpg";

    // THIS FAILS
    // String[] testArraySplit = TextUtils.split(arrayNBOW, ",");

    // THIS WORKS
    String[] testArraySplit = TextUtils.split(testArray, ",");

    adapter=new LazyAdapter(this, testArraySplit);
 list.setAdapter(adapter);

    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(listener);

    Button c=(Button)findViewById(R.id.button2);
    c.setOnClickListener(loadtext);

}

事先感谢你向我提供的任何建议或协助!

www.un.org/Depts/DGACM/index_spanish.htm 禁止使用杀伤人员地雷:

public class MainActivity extends Activity {

ListView list;
LazyAdapter adapter;
List<String> strings = new ArrayList<String>();
String readString = new String();
String arrayNBOW;
String[] nardsArray;
String nards;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

/ 新的解决办法

  File sdcard = Environment.getExternalStorageDirectory();
  File file = new File(sdcard,"/LazyList/gkindex.txt");
  StringBuilder text = new StringBuilder();

  try {
      BufferedReader br = new BufferedReader(new FileReader(file));
      String line;

      while ((line = br.readLine()) != null) {
          text.append(line);
          text.append( 
 );
          nards = text.toString();
          nardsArray = TextUtils.split(nards, ",");
      }
  }
  catch (IOException e) {
      Toast.makeText(MainActivity.this, "FAIL: "+e, Toast.LENGTH_LONG).show();
  }

/ 最终新解决方案

    Toast.makeText(MainActivity.this, "FILE-READ: "+nardsArray, Toast.LENGTH_LONG).show();

    setContentView(R.layout.main);
    list=(ListView)findViewById(R.id.list);

    adapter=new LazyAdapter(this, nardsArray);
    list.setAdapter(adapter);

    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(listener);

    Button c=(Button)findViewById(R.id.button2);
    c.setOnClickListener(loadtext);

}
最佳回答

我怀疑你们的读物没有工作。 首先,我注意到,没有关于关闭溪流的最后条款。 第二是,你在案卷结束前再行。 如果你在那里有一条空线的话? 单线“”检查。 您还应打破内容的第一行。

此外,我更喜欢使用一个像

这是否有助于?

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签