ArrayList + TextView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

ArrayList + TextView

Postby wolandino » Mon Jan 11, 2010 10:25 pm

Hello,
I have some code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. bla= (ListView) findViewById(R.id.list);
  3.  
  4. if (bla.getAdapter() == null) {
  5.  
  6.         adapter = new BlaManagerAdapter(this, 0, somedata);
  7.  
  8.         bla.setAdapter(adapter);
  9.  
  10.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Code working as I want.
Next I have code in BlaManagerAdapter. All elements of a ListView have TextView element, with setOnClickListener:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         private OnClickListener doclick= new OnClickListener() {
  3.  
  4.                 public void onClick(View v) {
  5.  
  6.                         XXX data = (XXX) v.getTag();
  7.  
  8.                         View upd = mInflater.inflate(R.layout.main, null);
  9.  
  10.                         EditText updstatus = (EditText) upd.findViewById(R.id.updatestatus);
  11.  
  12.                         updstatus.setText(XXX.someString);
  13.  
  14.                         Log.d(TAG,"LOGIN: "+updstatus.getText().toString());
  15.  
  16.                 }
  17.  
  18.         };
  19.  
  20.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


If we check LogCat we got: "Login: our_nick", but updatestatus on form hasn`t text. What should I do here, to get text in updatestatus TextView?
wolandino
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 02, 2010 11:16 am

Top

Postby wolandino » Tue Jan 12, 2010 12:11 pm

Any ideas?
wolandino
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 02, 2010 11:16 am

Postby Droid123 » Tue Jan 12, 2010 1:33 pm

I don't really understand why you would create a new View in onClick, are you trying to replace the TextView in the ListView or something?

If you just want to change the text in an ListView row, then do:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private OnClickListener doclick= new OnClickListener() {
  2.  
  3.           public void onClick(View v) {
  4.  
  5.                TextView tv = (TextView) v.findViewById(R.id.yourtextview);
  6.  
  7.                tv.setText("yourcustomtextstring");
  8.  
  9.           }
  10.  
  11.      };
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

Postby wolandino » Tue Jan 12, 2010 2:06 pm

2Droid123,

I`m trying replace text in TextView not from ListView row.
If we will run your code we`ll get NullPointerException.

It is schematic image:

[TextViewHere] [some EditText]
[ListView]
[ListView row1 with TextViewRow1]
[ListView row2]
....
[ListView rown]
[/ListView]

I want to click on TextViewRow1 and set some text in TextViewHere.
I hope it will help :)
wolandino
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 02, 2010 11:16 am

Postby Droid123 » Tue Jan 12, 2010 2:51 pm

ah, now I understand :) Make sure you implement onITEMclicklistener. Something like this should work:

global variable:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. TextView tvhere;
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


in onCreate:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. tvhere = (TextView)findViewById(R.id.textviewhere);
  2.  
  3.         ListView l = (ListView)findViewById(R.id.yourlistview);
  4.  
  5.         l.setOnItemClickListener(new OnItemClickListener() {
  6.  
  7.  
  8.  
  9.                         @Override
  10.  
  11.                         public void onItemClick(AdapterView<?> av, View v, int index, long arg3) {
  12.  
  13.                                 TextView tvrow = (TextView) av.getChildAt(index);
  14.  
  15.                                 tvhere.setText(tvrow.getText());
  16.  
  17.                         }
  18.  
  19.                
  20.  
  21.         });
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


You should still set the arrayadapter and maybe you'll need to call .invalidate() on the parent Viewgroup
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

Postby wolandino » Tue Jan 12, 2010 4:03 pm

No...) It is not so simple:)
I don`t want click on ListView item! I want click on TextView inside ListView row.
But ListView row has structure like:

[TextView1] [TextView1] [TextView3] for example.

Roughly, And I want to after click on TextView1 TextViewHere got some text. fuf:)

If have some questions - you are welcome)
wolandino
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 02, 2010 11:16 am

Top

Postby Droid123 » Tue Jan 12, 2010 5:04 pm

Hmmm then I'm at a loss about what you're trying to accomplish..

But you could still use the code above, do a View.findViewById(R.id.specifictextview) on the View-parameter of the selected Item in OnItemClickListener, to get a handle to a specific TextView inside the row.

Or do you want a ListView that detects which part of the row you are clicking? Can't help you there, but there are plenty of similar questions on the forum
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests