Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ArrayAdapter list layout - Right Align

Posted on 2011-03-20
11
Medium Priority
?
1,017 Views
Last Modified: 2012-05-11
Hi experts,
 I have an Android application wich displays RSS by ArrayAdapter list
 
 here is the code to display the Array Adapter:
          ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,
                      android.R.layout.simple_list_item_1,myRssFeed.getList());
          setListAdapter(adapter);  


How do I set the layoput be Rigth Alinged ?? ( by default it's left Aligned)

Thanks Alot
0
Comment
Question by:madmare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 35178961

Use the gravity attribute:

setGravity(Gravity.RIGHT);

0
 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 35178966

madmare, I already answered to your similar question here:

http://www.experts-exchange.com/Programming/Languages/Java/Android/Q_26859493.html?sfQueryTermInfo=1+10+30+android+rtl

but you did not post any reply.

Please post the complete code, so I can see why you dont have it right alligned. The example I posted in the other question, works on my emulator.
0
 

Author Comment

by:madmare
ID: 35178980

 I got: setGravity is undefined method

 can you please be more specific , i'm new in Android development

thanks in advanced



0
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 35179019


You have to use setGravity on the object that has that method defined. For example LinearLayout:

http://developer.android.com/reference/android/widget/LinearLayout.html


If you cant find it, post the complete code, otherways I cant see where is the problem.
0
 

Author Comment

by:madmare
ID: 35179030
This is my Code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    LinearLayout layout = new LinearLayout(this);

    try {

          URL rssUrl = new URL("http://www.aaaa.com/rssservice/V.aspx");          
          SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
          SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
          XMLReader myXMLReader = mySAXParser.getXMLReader();
          RSSHandler myRSSHandler = new RSSHandler();
          myXMLReader.setContentHandler(myRSSHandler);
          InputSource myInputSource = new InputSource(rssUrl.openStream());
          myXMLReader.parse(myInputSource);

          myRssFeed = myRSSHandler.getFeed();

    } catch (MalformedURLException e) {
      
          e.printStackTrace();
    } catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
          e.printStackTrace();
    } catch (SAXException e) {
// TODO Auto-generated catch block
          e.printStackTrace();
    } catch (IOException e) {
// TODO Auto-generated catch block
          e.printStackTrace();
            }

    if (myRssFeed!=null)
    {
          TextView feedTitle = (TextView)findViewById(R.id.feedtitle);          
          TextView feedDescribtion = (TextView)findViewById(R.id.feeddescribtion);
          TextView feedPubdate = (TextView)findViewById(R.id.feedpubdate);
          TextView feedLink = (TextView)findViewById(R.id.feedlink);
          
          feedTitle.setText(myRssFeed.getTitle());
          feedTitle.setGravity(Gravity.RIGHT);
          
          feedDescribtion.setText(myRssFeed.getDescription());
          feedDescribtion.setGravity(Gravity.RIGHT);
          
          //feedPubdate.setText(myRssFeed.getPubdate());
          //feedPubdate.setGravity(Gravity.RIGHT);
          
          //feedLink.setText(myRssFeed.getLink());
          //feedLink.setGravity(Gravity.RIGHT);
          
          LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
          
          
          
          ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,
                      android.R.layout.simple_list_item_1,myRssFeed.getList());    
          setListAdapter(adapter);

            }
      }
}
0
 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 35179053


Please add the class definition, so I can see what you are extending here. I just need the line which starts with:

public class .... extends ....
0
 

Author Comment

by:madmare
ID: 35179063
public class AndroidRssReader extends ListActivity {

private RSSFeed myRssFeed = null;
0
 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 35179080

Ok, thx. I'll take a look later today.
0
 
LVL 17

Accepted Solution

by:
Dejan Pažin earned 2000 total points
ID: 35179516
What you need is your own adapter. Here is everything you need:

1. Add the class below to your code
2. Change this line:

 ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this, android.R.layout.simple_list_item_1,myRssFeed.getList());    

into this:

 RightAlignedAdapter<RSSItem> adapter = new RightAlignedAdapter<RSSItem>(this, android.R.layout.simple_list_item_1,myRssFeed.getList());    


public class RightAlignedAdapter<K> extends  ArrayAdapter<K> {


        public RightAlignedAdapter(Context context, int resource, List<K> objects) {
            super(context, resource, objects);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView view = (TextView)super.getView(position, convertView, parent);
            view.setGravity(Gravity.RIGHT);
            return view;
        }

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            TextView view = (TextView)super.getView(position, convertView, parent);
            view.setGravity(Gravity.RIGHT);
            return view;
        }
    }

Open in new window

0
 

Author Comment

by:madmare
ID: 35179598
it's work wonderful

 Thanks you
0
 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 35179661

I'm glad it works for you.

This is also connected to your other questin about right alignement:

http://www.experts-exchange.com/Programming/Languages/Java/Android/Q_26859493.html?sfQueryTermInfo=1+10+30+android+rtl

Now would be a good time to check if the last answer on that question works.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, people trade privacy and security for convenience. However in today's concrete jungle, this is an extremely foolish decision considering the vast amount of technologies being used against consumer interest. First off, I won't waste any time e…
Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question