Friday, December 7, 2012

ScrollView with Button on Bottom in Android


ScrollView with Button on Bottom in Android

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="wrap_content" android:layout_width="fill_parent">
     <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="This text view should act as header  " />
     <ScrollView android:layout_marginBottom="50dip" android:id="@+id/ScrollView01" android:layout_height="wrap_content" android:layout_width="fill_parent">
          <RadioGroup android:id="@+id/RadioGroup01" android:layout_width="wrap_content" android:layout_height="wrap_content">
               <RadioButton android:id="@+id/RadioButton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />       
          </RadioGroup>
     </ScrollView>
     <RelativeLayout android:layout_marginTop="-50dip" android:gravity="bottom" android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1">
         <TableRow>
        <Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="One"/>
        <Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Two" android:layout_gravity="center_vertical"/>
        <Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Three" android:layout_gravity="right"/>
      </TableRow>
      </TableLayout>
     </RelativeLayout>
</LinearLayout>

Thursday, November 22, 2012

Send Email with Attachment in iphone

Send Email with Attachment in iphone

1) In Xcode 4 goto the build phases tab for your target. Make sure you see MessageUI.framework. If it's not there click + to add a new framework.

2)In your interface file


#import <MessageUI/MFMailComposeViewController.h>


@interface YourViewController : UIViewController <MFMailComposeViewControllerDelegate> 


3)Add this Method


-(void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Check My Image!"];

    // Set up recipients
    // NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"];
    // NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
    // NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];

    // [picker setToRecipients:toRecipients];
    // [picker setCcRecipients:ccRecipients];  
    // [picker setBccRecipients:bccRecipients];

    // Attach an image to the email
    UIImage *myImage = YourImage;
    NSData *myData = UIImagePNGRepresentation(
myImage);
    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"
myImage.png"];

    // Fill out the email body text
    NSString *emailBody = @"My Pic";
    [picker setMessageBody:emailBody isHTML:NO];
    [self presentModalViewController:picker animated:YES];

    [picker release];
}


4) Implement the delegate method

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{  
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Result: canceled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Result: saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Result: sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Result: failed");
            break;
        default:
            NSLog(@"Result: not sent");
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}




Sunday, November 18, 2012

Recieve SMS and show it in Activity as DialogBox

Recieve SMS and show it in Activity as DialogBox


Source Code

Thursday, November 15, 2012

Take SnapShot and save in gallery in iphone

Take SnapShot and Save in gallery in iphone

canvasView is UIView. if you want to take snapshot of whole screen use self.view.

    UIGraphicsBeginImageContext(canvasView.frame.size);
    [canvasView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

Wednesday, November 14, 2012

Drag UIImageVIew ( touch Event ) in iphone


Drag UIImageVIew ( touch Event ) in iphone

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
blockView.center = location;   // blockView = UIimageView which you want to drag
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}

Thursday, November 8, 2012

Custom Color in Iphone and Core Plot

Custom Color in Iphone and Core Plot



Add Custom Color in Iphone

[UIColor colorWithRed:0.47 green:0.77 blue:0.37 alpha:1.0



Add Custom Color in Core-Plot

[CPTColor colorWithComponentRed:0.47 green:0.77 blue:0.37 alpha:1.0];

Thursday, November 1, 2012

Merge two NSDictionary in one NSDictionary ( if keyvalues are same )

Merge two NSDictionary in one NSDictionary ( if keyvalues are same )


NSMutableDictionary *combined = [your_nsdictionary mutableCopy];
    for(NSString *key in [combined allKeys])
    {
        NSString *breakfastDate = [your_nsdictionary valueForKey:key];
        NSString *dinnerDate = [your_nsdictionarytwo objectForKey:key];
        if(dinnerDate){
            [combined setObject:[NSString stringWithFormat:@"%@,%@",breakfastDate, dinnerDate] forKey:key];
            } else {
                [combined setObject:[NSString stringWithFormat:@"%@,0",breakfastDate] forKey:key];
                }
    }
    NSLog(@"Combine %@",combined);

Remove Duplicate Values from NSMutableArray iPhone

Remove Duplicate Values from NSMutableArray iPhone

NSArray *copy = [mutableArray copy];
NSInteger index = [copy count] - 1;
for (id object in [copy reverseObjectEnumerator]) {
    if ([mutableArray indexOfObject:object inRange:NSMakeRange(0, index)] != NSNotFound) {
        [mutableArray removeObjectAtIndex:index];
    }
    index--;
}
[copy release];

Thursday, October 25, 2012

Split one string into different strings iPhone


Split one string into different strings



NSString *str = @"011597464952,01521545545,454545474,454545444|Hello this is were the message is.";
    
    NSArray *firstSplit = [str componentsSeparatedByString:@"|"];
    NSAssert(firstSplit.count == 2@"Oops! Parsed string had more than one |, no message or no numbers.");
    NSString *msg = [firstSplit lastObject];
    NSArray *numbers = [[firstSplit objectAtIndex:0componentsSepratedByString:@","];
    
    // print out the numbers (as strings)
    for(NSString *currentNumberString in number) {
        NSLog(@"Number: %@", currentNumberString);
    }

Wednesday, October 24, 2012

IPhone Custom Toolbar on Keyboard to Hide keyboard

IPhone Custom Toolbar on Keyboard

MY requirement was to work on numeric keys not alphabets so i have used Numeric Pad on UITEXTFIELD  and you all know that by default there is no button on numeric pad for hidden keyboard. You have to create Custom Button on ur numeric pad and call [numberTextField resignFirstResponder]; to hide numeric pad.

Solution

I have create a custom toolbar and have put two buttons on it 1) Apply and 2) Cancel. And created a method for both buttons.


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    numberToolbar.barStyle = UIBarStyleBlackTranslucent;
    numberToolbar.items = [NSArray arrayWithObjects:
                           [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
                           [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                           [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
                           nil];
    [numberToolbar sizeToFit];
    numberTextField.inputAccessoryView = numberToolbar;
}

-(void)cancelNumberPad{
    [numberTextField resignFirstResponder];
    numberTextField.text = @"";
}

-(void)doneWithNumberPad{
    NSString *numberFromTheKeyboard = numberTextField.text;
    [numberTextField resignFirstResponder];
}

Thats it .. 
You can add Custom button on left side of 0 button. 



Tuesday, October 23, 2012

How To Install Android SDK


How To Install Android SDK
Here you will get complete guide how to install android SDK on you computer to get started will android. Installing android is not a big deal but there are 3 to 4 things to install to get started and that's what makes android installation complicated for some user.

Step 1
For Android SDK you must have Windows XP, Windows Vista or Windows 7.

Step 2
Install JDK or JRE



http://www.oracle.com/technetwork/java/javase/downloads/index.html

Step 3
Install Eclipse





For 32 bit
http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.6.1-201009090800/eclipse-SDK-3.6.1-win32.zip

For 64 bit
http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.6.1-201009090800/eclipse-SDK-3.6.1-win32-x86_64.zip


Step 4
Install Android SDK



http://developer.android.com/sdk/index.html

Step 5

http://developer.android.com/sdk/eclipse-adt.html

After installing Eclipse and Android SDK you must install Android Development Tools (ADT) Plugin to built android project in eclipse.

1- Start Eclipse then Help -> Install New Software
2- Click Add, in the top-right corner.
3- In the Add Repository dialog that appears, type  following URL for the Location:

    https://dl-ssl.google.com/android/eclipse/

4-In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
5-In the next window, you'll see a list of the tools to be downloaded. Click Next.
6-Read and accept the license agreements, then click Finish.
7-When the installation completes, restart Eclipse

Step 6
Open Eclipse then Windows . If you will see Android SDK and AVD Manager then it mean that you can now start development in android
If you don't see Android Project in New then go to Other and select Android Project.
After Selecting Android Project if Built Target is empty then go to Windows ->  Preferences and select android then locate you installed SDK in SDK location 

Click here to get all links that will help you to install android SDK


Core Plot Custom Themes in iPhone

Core Plot Custom Themes in iPhone


    CPTheme *theme = [CPTheme themeNamed:kCPPlainWhiteTheme]; 
    graph = (CPXYGraph *)[theme newGraph];
    
    graph.fill = [CPFill fillWithColor:[CPColor clearColor]];
    graph.plotAreaFrame.fill = [CPFill fillWithColor:[CPColor clearColor]];

You can apply following Themes in Core Plot

themeNamed:kCPPlainWhiteTheme
themeNamed:kCPTDarkGradientTheme
themeNamed:kCPTPlainBlackTheme
themeNamed:kCPTSlateTheme
themeNamed:kCPTStocksTheme

Multiple PickerViews in one View


Multiple PickerViews in one View


Solution

if([pickerView isEqual:pickerView2])
    {
        return 3;
    }
    if ([pickerView isEqual:pickerView1]) {
        return 4;
    }


Complete Source Code

ViewController.h

@interface ViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>
{
    IBOutlet UILabel *mlabel;
    NSMutableArray *arrayNo;
    IBOutlet UIPickerView *pickerView2;
    NSMutableArray *arrayNo1;
    IBOutlet UIPickerView *pickerView1;

}
@property (nonatomic, retain) UILabel *mlabel;
@end

ViewController.m

#import "ViewController.h"

@implementation ViewController
@synthesize mlabel;

- (void)viewDidLoad
{
[super viewDidLoad];
arrayNo = [[NSMutableArray alloc] init];
[arrayNo addObject:@" 100 "];
[arrayNo addObject:@" 200 "];
[arrayNo addObject:@" 400 "];
[arrayNo addObject:@" 600 "];
[arrayNo addObject:@" 1000 "];
[pickerView2 selectRow:1 inComponent:0 animated:NO];
    
    arrayNo1 = [[NSMutableArray alloc] init];
[arrayNo1 addObject:@" 1001 "];
[arrayNo1 addObject:@" 2001 "];
[arrayNo1 addObject:@" 4001 "];
[arrayNo1 addObject:@" 6001 "];
[arrayNo1 addObject:@" 10001 "];
[pickerView1 selectRow:1 inComponent:0 animated:NO];
    
    mlabel.text= [arrayNo1 objectAtIndex:[pickerView2 selectedRowInComponent:0]];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    if([pickerView isEqual:pickerView2])
    {
        return 1;
    }
    if ([pickerView isEqual:pickerView1]) {
        return 1;
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if([pickerView isEqual:pickerView2])
    {
        mlabel.text= [arrayNo objectAtIndex:row];
    }
    if ([pickerView isEqual:pickerView1]) {
        mlabel.text= [arrayNo1 objectAtIndex:row];
    }
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
if([pickerView isEqual:pickerView2])
    {
        return 3;
    }
    if ([pickerView isEqual:pickerView1]) {
        return 4;
    }
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
    if([pickerView isEqual:pickerView2])
    {
        return [arrayNo objectAtIndex:row];
    }
    if ([pickerView isEqual:pickerView1]) {
        return [arrayNo1 objectAtIndex:row];
    }
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload
{

}

- (void)dealloc {
    [super dealloc];
}

@end

ViewController.XIB


2 UIPicker and 1 UILabel
Connect Datasource and delegate of both picker to file owner.
NOTE:-
Sorry for naming convention. You can achieve this multi picker by using one pickerView and divide it in number of columns.
In numberOfComponentsInPickerView return how many columns you want in one pickerView.

Loaded nib but the view outlet was not set



Loaded nib but the view outlet was not set

I was working on my iPhone project . And i copied Components from one nib file to another and when i run that project it gave this error. It happen when you copy nib components to another nib or sometime when you open new nib File.

Solution
  • Open the XIB file causing problems
  • Click on file's owner icon on the left bar (top one, looks like a yellow outlined box)
  • If you don't see the right-hand sidebar, click on the third icon above "view" in your toolbar. This will show the right-hand sidebar
  • In the right-hand sidebar, click on the third tab--the one that looks a bit like a newspaper
  • Under "Custom Class" at the top, make sure Class is the name of the ViewController that should correspond to this view. If not, enter it
  • In the right-hand sidebar, click on the last tab--the one that looks like a circle with an arrow in it
  • You should see "outlets" with "view" under it. Drag the circle next to it over to the "view" icon on the left bar (bottom one, looks like a white square with a thick gray outline
  • Save the xib and re-run



Monday, October 22, 2012

Android Grid View


In java file
GirdView_Act.java


package GirdView.app;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

public class GirdView_Act extends Activity implements
AdapterView.OnItemSelectedListener {
TextView selection;
String[] items = { "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "thirteen", "fouteen", "fifteen",
"sixteen", "seventeen", "eighteen", "ninteen", "twenty",
"twenty one", "twenty two", "twenty three", "twenty four",
"twenty five", "twenty six", "twenty seven", "twenty eight",
"twenty nine", "thirty", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten", "eleven", "thirteen",
"fouteen", "fifteen", "sixteen", "seventeen", "eighteen",
"ninteen", "twenty", "twenty one", "twenty two", "twenty three",
"twenty four", "twenty five", "twenty six", "twenty seven",
"twenty eight", "twenty nine", "thirty", };

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
GridView g = (GridView) findViewById(R.id.grid);
g.setAdapter(new FunnyLookingAdapter(this,
android.R.layout.simple_list_item_1, items));
g.setOnItemSelectedListener(this);
}

public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
selection.setText(items[position]);
}

public void onNothingSelected(AdapterView<?> parent) {
selection.setText("");
}

private class FunnyLookingAdapter extends ArrayAdapter {
Context ctxt;

@SuppressWarnings("unchecked")
FunnyLookingAdapter(Context ctxt, int resource, String[] items) {
super(ctxt, resource, items);
this.ctxt = ctxt;
}

public View getView(final int position, View convertView,
ViewGroup parent) {
TextView label = (TextView) convertView;
if (convertView == null) {
convertView = new TextView(ctxt);
label = (TextView) convertView;
}
label.setText(items[position]);
return (convertView);
}
}
}

In xml files
main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<GridView
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:verticalSpacing="35px"
android:horizontalSpacing="5px"
android:numColumns="auto_fit"
android:columnWidth="100px"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</LinearLayout>



Android List View ( using EfficientAdapter)


In java file


package ListView.app;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class my_listview extends Activity {
ListView itemList = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview2);
// TODO Auto-generated method stub
itemList = (ListView) findViewById(R.id.itemList);
itemList.setAdapter(new EfficientAdapter(this));
}

String[] Qitems = {"Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10", "Q11", "Q12", "Q13", "Q14", "Q15"};

String[] Aitems = { "Ans1", "Ans2", "Ans3", "Ans4", "Ans5", "Ans6", "Ans7", "Ans8", "Ans9", "Ans10", "Ans11", "Ans12", "Ans13", "Ans14", "Ans15" };

public class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public Context ctxt;

public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.ctxt = context;
}

public int getCount() {
return Qitems.length;
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}


public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;

if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_listview, null);
holder = new ViewHolder();
holder.titletxt = (TextView) convertView.findViewById(R.id.titletxt);
holder.ratingtxt = (TextView) convertView.findViewById(R.id.ratingtxt);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ratingtxt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), Aitems[position],Toast.LENGTH_LONG).show();
}
});

holder.titletxt.setText(Qitems[position]);
holder.ratingtxt.setText("Answer");

return convertView;
}

class ViewHolder {
TextView titletxt;
TextView ratingtxt;

}
}
}

In first xml file (.xml)

custom_listview.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:id="@+id/titletxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:textColor="#ffffff"
android:textSize="18sp"
android:text="fasdsadsad"
android:textStyle="bold">
</TextView>
<TextView
android:id="@+id/ratingtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:textColor="#ffffff"
android:text="123"
android:layout_below="@+id/titletxt"
android:textSize="10sp">
</TextView>
</RelativeLayout>
</LinearLayout>

In second xml file (.xml)

listview2

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/ImageView1"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="@drawable/icon">
</ImageView>
<ListView
android:layout_below="@+id/ImageView1"
android:id="@+id/itemList"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:background="#20000000">
</ListView>
</RelativeLayout>

Note :- Question and Answers in String Qitem and Aitems are just for example.