TEL:400-8793-956
当前位置:程序、服务器

如何在解析为textView时检索多列数据

提问者: 近期获赞: 浏览人数: 发布时间:2021-02-22 09:14:05

 问:因此,我遵循了构建自毁应用程序的过程。我正在尝试此新功能,用户可以创建发送到其他用户的收件箱的调查表,并且当用户单击该框时,数据将在另一个活动中显示为textView。基本上,我能够在解析中存储数据,但是即使我按照教程中的说明进行操作,检索数据也成为一个问题。请帮我看看我在想什么。下面的代码用于说明:

 
用户创建问卷的VoteActivity:公共类VoteActivity扩展了Activity {
 
私人投票;
私有EditText mainText;
私有EditText mTextOne;
私人EditText mTextTwo;
私人EditText mTextThree;
私有字符串postmaintText;
私有字符串posttextOne;
private String posttextTwo;
private String posttextThree;
私人Button mButton;
@Override
 protected void onCreate(Bundle savedInstanceState){
     super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vote);
    意图意图= this.getIntent();
     mainText =(EditText)findViewById(R.id.questionVote);
     mTextOne =(EditText)findViewById(R.id.choiceOne);
 
     mTextTwo =(EditText)findViewById(R.id.choiceTwo);
     mTextThree =(EditText)findViewById(R.id.choiceThree);
     mButton =(按钮)findViewById(R.id.createQ);
     mButton.setOnClickListener(new View.OnClickListener(){          @
 Override
          public void onClick(View v){
              postmaintText = mainText.getText()。toString();
              posttextOne = mTextOne.getText()。toString();
              posttextTwo = mTextTwo.getText ().toString();
              posttextThree = mTextThree.getText()。toString();
              postmaintText.trim();
              posttextOne.trim();
              posttextTwo.trim();
              posttextThree.trim();
 
 
             如果(postmaintText.isEmpty()|| posttextOne.isEmpty()|| posttextTwo.isEmpty()|| posttextThree.isEmpty())
              {
                  AlertDialog.Builder builder = new AlertDialog.Builder(VoteActivity.this);
                 builder.setMessage(R.string.voteMessage)
                          .setTitle(R.string.vote_error_title)
                          .setPositiveButton(android.R.string.ok,null);
                 AlertDialog对话框= builder.create();
                 dialog.show();
             }
              else
              {
                  final ParseObject post = new ParseObject(“ Messages”);
                 post.put(“ questionare”,postmaintText);
                 post.put(“ optionOne”,posttextOne);
                 post.put(“ optionTwo”,posttextTwo);
                 post.put(“ optionThree”,posttextThree);
                 post.saveInBackground(new SaveCallback(){                      @
 Override
                      public void done(ParseException e){
                      if(e == null){
                      //发问者成功
                         Intent intent = new Intent(VoteActivity.this,receptorsActivity.class);
                         投票= new投票(post.getObjectId(),postmaintText,posttextOne,posttextTwo,posttextThree);
                         字符串mainTextt = mainText.getText()。toString();
 
                         字符串optionOnee = mTextOne.getText()。toString();
                         字符串optionTwoo = mTextTwo.getText()。toString();
                         字符串optionThree = mTextThree.getText()。toString();
                         //以下是将向用户显示                         配方列表的意图,即应用程序崩溃的
意图intent.putExtra(parseConstants.MAIN_QUESTIONRARE,mainTextt);
                         intent.putExtra(parseConstants.OPTION_ONE,optionOnee);
                         intent.putExtra(parseConstants.OPTION_TWO,optionTwoo);
                         intent.putExtra(parseConstants.OPTION_THREE,optionThree);
                         intent.putExtra(parseConstants.KEY_FILE_TYPE,parseConstants.TYPE_QUESTIONARE);
                         Toast.makeText(getApplication(),“已发送”,Toast.LENGTH_SHORT).show();
                         startActivity(intent);
                     }
                      else {
                          Toast.makeText(getApplicationContext(),“发布失败”,Toast.LENGTH_SHORT).show();
                     }
                      }
                  });
             }
          }
      });
}
 @Override
 public boolean onCreateOptionsMenu(Menu menu){
     //膨胀菜单;这会将项目添加到操作栏(如果有)。
 
 
    getMenuInflater()。inflate(R.menu.menu_vote,menu);
    返回true;
}
 @Override
 public boolean onOptionsItemSelected(MenuItem item){
     //处理操作栏项目在这里单击。    只要    您在AndroidManifest.xml中指定父活动,//操作栏就会
自动处理Home / Up按钮上的单击
    int id = item.getItemId();
    // noinspection SimplifiableIfStatement
     if(id == R.id.action_settings){
         return true;
    }
     return super.onOptionsItemSelected(item);
}
 
 
 
}
 
InboxFragment:公共类InboxFragment扩展了ListFragment {
 
保护的列表<的parseObject > mMessages;
@Override
 public View onCreateView(LayoutInflater inflater,ViewGroup container,
                          Bundle savedInstanceState){
     View rootView = inflater.inflate(R.layout.fragment_inbox,container,false);
    返回rootView;
}
 //我们要查询我们刚刚在解析创建新的消息类
@覆盖
公共无效的onResume(){
     super.onResume();
    getActivity()。setProgressBarIndeterminate(true);
    ParseQuery <的parseObject >查询=新ParseQuery <的parseObject >
 
(parseConstants.CLASS_MESSAGES);
    query.whereEqualTo(parseConstants.KEY_RECIPIENT_IDS,ParseUser.getCurrentUser()。getObjectId());
    query.addDescendingOrder(parseConstants.KEY_CREATED_AT);
    query.findInBackground(新FindCallback <的parseObject >(){
         @覆盖
        公共无效完成(名单<的parseObject >消息,ParseException的E){
             getActivity()setProgressBarIndeterminate(假);
            如果(E == NULL){
                 //我们找到的消息!
                 mMessages =消息;
                 String []用户名=新的String [mMessages.size()];
 
                int i = 0;
                对于(ParseObject消息:mMessages){
                    用户名[i] = message.getString(parseConstants.KEY_SENDER_NAME);
                    i ++;
                }
                 //检查列表
               messageAdapter adapter = new messageAdapter(
                        getListView()。getContext(),
                        mMessages);
                setListAdapter(adapter);
            }
         }
     });
}
 @覆盖
公共无效onListItemClick(ListView的升,视图V,INT位置,长ID){
     super.onListItemClick(L,V,位置,ID);
 
    ParseObject消息= mMessages.get(位置);
    字符串messageType = message.getString(parseConstants.KEY_FILE_TYPE);
    字符串senderName = message.getString(parseConstants.KEY_SENDER_NAME);
    字符串displayMessage = message.getString(parseConstants.KEY_MESSAGE);
    字符串createdDate = message.getString(parseConstants.KEY_CREATED_AT);
    ParseFile文件= message.getParseFile(parseConstants.KEY_FILE);
    if(messageType.equals(parseConstants.TYPE_IMAGE)){
         //查看图片
        Uri fileUri = Uri.parse(file.getUrl());
        Intent intent = new Intent(getActivity(),ViewImageActivity.class);
        intent.setData(fileUri);
        startActivity(intent);
 
    }否则,如果(messageType.equals(parseConstants.TYPE_VIDEO)){
         Uri fileUri = Uri.parse(file.getUrl());
        //观看视频
        Intent intent = new Intent(Intent.ACTION_VIEW,fileUri);
        intent.setDataAndType(fileUri,“ video / *”);
        startActivity(intent);
    }
       否则if(messageType.equals(parseConstants.TYPE_QUESTIONARE)){
       // AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        Intent intent = new Intent(getActivity(),VoteAnswer.class);
        startActivity(intent);
    }否则if(messageType.equals(parseConstants.TYPE_TEXT)){
         //Toast.makeText(getActivity(),displayMessage,Toast.LENGTH_LONG).show();
 
        AlertDialog.Builder builder =新的AlertDialog.Builder(getActivity());
        builder.setTitle(“消息来自:” + senderName +“。”);
        builder.setMessage(displayMessage);
        builder.setPositiveButton(“ Ok”,新的DialogInterface.OnClickListener(){
             public void onClick(DialogInterface dialog,int whichButton){
             }
         });
        AlertDialog对话框= builder.create();
        dialog.show();
    }
     //删除消息
    列表< String > ids = message.getList(parseConstants.KEY_RECIPIENT_IDS);
    if(ids.size()== 1){
         //最后一个收件人,删除邮件
 
        message.deleteInBackground();
    } else {
         //删除收件人的名字
        ids.remove(ParseUser.getCurrentUser()。getObjectId());
        ArrayList < String > idsToRemove = new ArrayList < String >();
        idsToRemove.add(ParseUser.getCurrentUser()。getObjectId());
        message.removeAll(parseConstants.KEY_RECIPIENT_IDS,idsToRemove);
        message.saveInBackground();
    }
 }
     }
最后,投票答案://这里是我遇到问题的地方?
 
 
答:公共类VoteAnswer扩展了ActionBarActivity {
 
受保护的TextView问题;
受保护的TextView mOne;
受保护的TextView mTwo;
受保护的TextView mThree;
私有字符串问题;
私有String mO;
私有String mT;
私有字符串mH;
私人列表<投票> mVotes;
字符串obj;
@Override
 protected void onCreate(Bundle savedInstanceState){
     super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vote_answer);
    Questionare =(TextView)findViewById(R.id.mainQ);
    mOne =(TextView)findViewById(R.id.optionO);
    mTwo =(TextView)findViewById(R.id.optionTW);
 
    mThree =(TextView)findViewById(R.id.optionTH);
    getDetails();
    意图i = getIntent();
   // obj = i.getStringExtra(“ questionare”);
// getDetails(obj);
}
   私人无效getDetails(){
        ParseQuery <的parseObject >查询= ParseQuery.getQuery( “消息”);
       query.whereEqualTo(“ objectId”,ParseUser.getCurrentUser()。getObjectId());
       query.findInBackground(新FindCallback <的parseObject >(){
            @覆盖
           公共无效DONE(列表<的parseObject >目的,ParseException的发送){
 
               if(e == null){
                   for(int i = 0; i < objects.size (); i ++){ Questionare 。的setText (对象。让(我)的getString ( “ questionare ”)); MONE 。的setText (对象。让(我)的getString ( “ optionOne ”)); mTwo 。的setText (对象。让(我)的getString  
                      
                      (“ optionTwo ”)); 
三。的setText (对象。让(我)的getString ( “ optionThree ”)); } //问题= objects.toString(“ questionare”); // mO = objects.toString(“ optionOne”); // mT = objects.toString(“ optionTwo”); // mH = objects.toString(“ optionThree”); // addData (); }其他{ e 。printStackTrace (); }                      
 
           } 
}); }     
上一篇: 为什么此添加属性代码不起作用?
下一篇: 为什么我的应用程序无法运行?