- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将数据从一个屏幕传递到另一个屏幕。第一个屏幕从 CSV 中读取数据并将数据放入数据库表中。任何无效的数据,例如年份字符串(整数),都会被捕获并存储在 errorItem 的 ArrayList 中,其中包含书名、作者、日期、isbn、副本和标签。我的程序已成功识别无效的 csv 条目,但是当我传递要显示的错误数据时, ListView 仅显示最后传递的条目并重复它。
这可能是什么问题?
主要代码
ArrayList<itemLink> errorList = new ArrayList<itemLink>();
int successCounter = 0;
int errorCounter = 0;
String[][] errors = new String[1][6];
String[] line = new String[6];
try {
int titleCol = -1, authorCol = -1, dateCol = -1, isbnCol = -1, quantityCol = -1, tagCol = -1;
CSVReader reader = new CSVReader(new FileReader(new File(Environment.getExternalStorageDirectory().getPath()+location)));
String [] nextLine;
nextLine = reader.readNext();
int index = 0;
int lineLength = nextLine.length;
while(titleCol < 0 && index < lineLength)
{
if(nextLine[index].contains("TITLE"))
titleCol = index;
index++;
}
index = 0;
while(authorCol < 0 && index < lineLength)
{
if(nextLine[index].contains("AUTHOR"))
authorCol = index;
index++;
}
index = 0;
while(dateCol < 0 && index < lineLength)
{
if(nextLine[index].contains("DATE"))
dateCol = index;
index++;
}
index = 0;
while(isbnCol < 0 && index < lineLength)
{
if(nextLine[index].contains("ISBN"))
isbnCol = index;
index++;
}
index = 0;
while(quantityCol < 0 && index < lineLength)
{
if(nextLine[index].contains("COPIES"))
quantityCol = index;
index++;
}
index = 0;
while(tagCol < 0 && index < lineLength)
{
if(nextLine[index].contains("TAGS"))
tagCol = index;
index++;
}
System.out.println(nextLine[titleCol]);
System.out.println(nextLine[authorCol]);
System.out.println(nextLine[dateCol]);
System.out.println(nextLine[isbnCol]);
System.out.println(nextLine[quantityCol]);
System.out.println(nextLine[tagCol]);
int counter = 0;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
/*
* nextLine[titleCol] = TITLE
* nextLine[authorCol] = AUTHOR
* nextLine[dateCol] = DATE
* nextLine[isbnCol] = ISBN
* nextLine[quantityCol] = QUANTITY
* nextLine[tagCol] = TAGS
*/
lineLength = nextLine.length;
if(nextLine[isbnCol].contains("0") || nextLine[isbnCol].contains("1")
|| nextLine[isbnCol].contains("2") || nextLine[isbnCol].contains("3")
|| nextLine[isbnCol].contains("4") || nextLine[isbnCol].contains("5")
|| nextLine[isbnCol].contains("6") || nextLine[isbnCol].contains("7")
|| nextLine[isbnCol].contains("8") || nextLine[isbnCol].contains("9"))
{
if(InventoryAdapter.isbnFoundInInventory(nextLine[isbnCol]) == false)
{
if(nextLine[dateCol].contains("0") || nextLine[dateCol].contains("1")
|| nextLine[dateCol].contains("2") || nextLine[dateCol].contains("3")
|| nextLine[dateCol].contains("4") || nextLine[dateCol].contains("5")
|| nextLine[dateCol].contains("6") || nextLine[dateCol].contains("7")
|| nextLine[dateCol].contains("8") || nextLine[dateCol].contains("9"))
line[2] = nextLine[dateCol];
else
line[2]="-9999";
if(nextLine[quantityCol].contains("0") || nextLine[quantityCol].contains("1")
|| nextLine[quantityCol].contains("2") || nextLine[quantityCol].contains("3")
|| nextLine[quantityCol].contains("4") || nextLine[quantityCol].contains("5")
|| nextLine[quantityCol].contains("6") || nextLine[quantityCol].contains("7")
|| nextLine[quantityCol].contains("8") || nextLine[quantityCol].contains("9"))
line[4] = nextLine[quantityCol];
else
line[4]="-9999";
if(tagCol < lineLength && nextLine[tagCol].length() > 0)
line[5] = nextLine[tagCol];
else
line[5] = "*ERROR*";
if(titleCol < lineLength && nextLine[titleCol].length() > 0)
line[0] = nextLine[titleCol];
else
line[0] = "*ERROR*";
if(authorCol < lineLength && nextLine[authorCol].length() > 0)
line[1] = nextLine[authorCol];
else
line[1] = "*ERROR*";
if(isbnCol < lineLength && nextLine[isbnCol].length() > 0)
line[3] = nextLine[isbnCol];
else
line[3] = "*ERROR*";
if(line[0].equals("*ERROR*") || line[1].equals("*ERROR*")
|| line[3].equals("*ERROR*")|| line[5].equals("*ERROR*")
|| line[2].equals("-9999")|| line[4].equals("-9999"))
{
System.out.println(counter+". ERROR FOUND: "+line[0]);
errorList.add(new itemLink(line[0], line[1], Integer.parseInt(line[2]),
line[3], Integer.parseInt(line[4]), line[5]));
errorCounter++;
}
else
{
System.out.println(counter+". SUCCESSFULLY ADDED: "+line[0]);
InventoryAdapter.insertEntry(line[0], line[1], line[3], Integer.parseInt(line[2]),
line[5], Integer.parseInt(line[4]), 14);
successCounter++;
}
}
}
counter++;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
progressDialog.dismiss();
Intent i=new Intent(InventorySyncScreen.this,SyncSuccessScreen.class);
i.putExtra("username",userName);
i.putExtra("numSuccess",successCounter);
i.putExtra("numError", errorCounter);
i.putExtra("errorList", errorList);
startActivity(i);
同步成功屏幕
Intent intent = getIntent();
final String userName = intent.getExtras().getString("username");
int numSuccess= intent.getExtras().getInt("numSuccess");
int numError= intent.getExtras().getInt("numError");
@SuppressWarnings("unchecked")
ArrayList<itemLink> errorList = (ArrayList<itemLink>) getIntent().getSerializableExtra("errorList");
textNumSuccess.setText("Items Successfully Synced: "+numSuccess);
textNumError.setText("Data Errors Found: "+numError);
// Set up array
String[] errors = new String[6];
for(int i = 0; i < errorList.size(); i++)
{
System.out.println("errors[0] = "+errors[0]);
errors[0] = errorList.get(i).title;
errors[1] = errorList.get(i).author;
errors[2] = ((Integer)errorList.get(i).date).toString();
errors[3] = errorList.get(i).isbn;
errors[4] = ((Integer)errorList.get(i).quantity).toString();
errors[5] = errorList.get(i).tags;
reportArray.add(new ErrorItem(i, errors));
}
// add data in custom adapter
errorAdapter = new CustomErrorAdapter(this, R.layout.errorlist_row, reportArray);
ListView dataList = (ListView) findViewById(R.id.errorlist_row);
dataList.setAdapter(errorAdapter);
自定义错误适配器
public class CustomErrorAdapter extends ArrayAdapter<ErrorItem> {
Context context;
int layoutResourceId;
LinearLayout linearMain;
ArrayList<ErrorItem> data = new ArrayList<ErrorItem>();
public CustomErrorAdapter(Context context, int layoutResourceId,
ArrayList<ErrorItem> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = null;
if (convertView == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
//Make sure the textview exists in this xml
} else {
row = convertView;
}
ErrorItem myItem = data.get(position);
TextView titleLabel = (TextView) row.findViewById(R.id.titleText);
titleLabel.setText(myItem.details[0]);
TextView authorLabel = (TextView) row.findViewById(R.id.authorText);
authorLabel.setText(myItem.details[1]);
TextView dateLabel = (TextView) row.findViewById(R.id.dateText);
dateLabel.setText(myItem.details[2]);
TextView isbnLabel = (TextView) row.findViewById(R.id.isbnText);
isbnLabel.setText(myItem.details[3]);
TextView copiesLabel = (TextView) row.findViewById(R.id.copiesText);
copiesLabel.setText(myItem.details[4]);
TextView tagLabel = (TextView) row.findViewById(R.id.tagText);
tagLabel.setText(myItem.details[5]);
if(myItem.details[5].equals("*ERROR*"))
tagLabel.setTextColor(Color.parseColor("#ff2626"));
if(myItem.details[2].equals("-9999"))
dateLabel.setTextColor(Color.parseColor("#ff2626"));
if(myItem.details[4].equals("-9999"))
copiesLabel.setTextColor(Color.parseColor("#ff2626"));
if(myItem.details[0].equals("*ERROR*"))
titleLabel.setTextColor(Color.parseColor("#ff2626"));
if(myItem.details[1].equals("*ERROR*"))
authorLabel.setTextColor(Color.parseColor("#ff2626"));
if(myItem.details[3].equals("*ERROR*"))
isbnLabel.setTextColor(Color.parseColor("#ff2626"));
return row;
}
}
错误项目
public class ErrorItem {
public int num;
public String[] details;
public ErrorItem(int num, String[] details) {
super();
this.details = details;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String[] getDetails() {
return details;
}
public void setDetails(String[] details) {
this.details = details;
}
}
日志显示日志显示 ArrayList 已正确传递到 SyncSuccessScreen。
01-22 01:42:51.327: I/System.out(8717): errors[0] = *ERROR*
01-22 01:42:51.327: I/System.out(8717): errors[0] = The big beautiful
01-22 01:42:51.327: I/System.out(8717): errors[0] = Pieces of my sister's life
最佳答案
您必须在类 Itemlink 上实现可序列化,并且必须从 getintent().getserialisableExtra()
例如:
public class Itemlink implements Serializable{
}传递值作为
intent.putExtra("key",value);
getvalue as `getintent().getSerilaziable.Extra("key")`
关于Android 通过 Intent 传递 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21275558/
如果我想为收藏创建一个 Intent 。 如果用户问“他最喜欢什么”,它会显示一些建议芯片 因此它会调用与该芯片相关的任何后续 Intent 。 最喜欢的饮料 最喜欢的食物 最喜欢的电影等 我还想直接
我确信有一些显而易见的事情,但还没有找到解决这个简单问题的方法。错误是在用户猜出正确答案时尝试启动另一个 Activity 的主要 Activity : Error:(85, 23) Unresolv
public class MainActivity extends Activity { Button b; //FrameLayout fl; @Override p
我对 intentService 有点困惑。文档说,如果您向 intentService 发送多个任务( Intent ),那么它将在一个单独的线程上一个接一个地执行它们。我的问题是 - 是否可以同时
我正在尝试从其他应用程序获取 mime 类型 text/plain 的 Intent 并将该文本存储在字符串类型的变量中。它在 onCreate 方法中工作正常,但是当我使用 singleTask 作
我想知道,2个代码有什么区别? newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
如何设置我的 Activity 以响应任何类型的共享 Intent 。 我试过:- 但是这不起作用,我已经阅读了http://developer.android.co
鉴于子类具有不同的上下文以及在单击监听器后启动的不同 Activity ,父类(super class)中的代码 Intent Intent=new Intent(context,Activity.c
更新#1:更多信息添加到这篇文章的末尾 我是 Android 开发和测试的新手。 我有 3 个 Espresso 测试。第一个测试通过,但第二个不会运行,因为在第二个测试之前调用 setUp() 方法
我是 Espresso UI 测试的新手。 我在运行测试时遇到这个错误(ADT Eclipse IDE)。 该应用程序已经开发完成,并且在启动该应用程序时有很多请求正在进行。无法重写应用程序。但我需要
因此,尝试创建一个我认为是基本简历应用程序的应用程序。我有两个类(class),都有同样的问题。它说它“无法解析符号 Intent ” 谷歌部分做了,但没有任何意义.. 这是我的代码。 MainAct
我正在尝试将 user_id 值从一个 Intent 传递到另一个 Intent。我知道这是一个非常简单的过程,而且我已经这样做了好几次了。但对于下面的代码,我有点困惑。 我需要将 user_id 值
这是我将值传递给名为 choice 的类的主要 Activity 。 @Override public void onClick(View v) { // TODO Auto-generated me
我正在寻找一个 Android Intent 来翻译文本,我发现了这个: Google Translate Activity not working anymore 但我想在任务管理器中使用它。我真的
可以设置多个启动 Intent ,例如,当用户点击通知时。 让我解释一下我的具体问题: 我有一个带通知的应用程序。每个通知都会打开一个不同的 Activity (也有不同的附加功能)。 现在我想提取有
我有一个 Intent launchIntent = packageManagerForListener.getLaunchIntentForPackage(packagesForAdapter[po
List targetedShareIntents = new ArrayList(); Intent shareIntent = new Intent(android.content.Intent.
所以我试图在选择列表中的项目后启动一个新 Activity ......根据我所读的内容非常基本。我也在尝试在附加功能中发送一个值。所以我可以选择列表中的项目,然后新 Activity 开始,extr
有没有一种方法可以将一个Intent bundle 从一个 Intent 传递到另一个 Intent ,而不必提取包并单独处理每个额外的 Intent ? 例子: intent2.setExtras(
这个问题在这里已经有了答案: Android 5.0 (L) Service Intent must be explicit in Google analytics (11 个答案) 关闭 6 个月
我是一名优秀的程序员,十分优秀!