Need to Scroll the view into RelativeLayout in a new Window in android

79 views Asked by At

I have 2 ListView and they are auto scrollable. So, when a select 2 items form those listViews A new window(Canvas) will open but i want to that newWindow(Canvas) scrollable. Because that canvas size is huge...

Need Help! Thanks in advance..

LAYOUT

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:paddingLeft="16dp"
   android:paddingRight="16dp" >

   <ListView
       android:id="@+id/list1"
       android:layout_width="60dp"
       android:layout_height="fill_parent"
       android:layout_alignParentLeft="true" />

   <ListView
       android:id="@+id/list2"
       android:layout_width="60dp"
       android:layout_height="fill_parent"
       android:layout_alignParentRight="true" />

   <View
       android:id="@+id/mapView"
       android:layout_width="60dp"
       android:layout_height="fill_parent"/>

</RelativeLayout>
  • I WANT THAT (VIEW) WILL SCROLLABLE IN A NEW WINDOW WHEN I WILL SELECTS 2 ITEMS FROM THE LISTVIEWS.

ACTIVITY SOURCE CODE

package com.example.tester1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
    Map map;
    String Source = "Blank";
    String Destination = "Blank";
    ListView list1;
    ListView list2;
    String [] listArray;
    BufferedReader AirportLocation;


    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            AirportLocation = new BufferedReader(
                    new InputStreamReader(getAssets().open("Airport-Location3.txt")));
        } catch (IOException e) {
            e.printStackTrace();
        }
        listArray = new String[1168];

        String line1;
        int c = 0;// location detector
        try {
            while((line1 = AirportLocation.readLine())!=null){
                StringTokenizer s = new StringTokenizer(line1);
                String airport = s.nextToken();
                listArray[c] = airport;
                c++;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


        list1 = (ListView) findViewById(R.id.list1);
        list2 = (ListView) findViewById(R.id.list2);
        ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listArray);
        ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listArray);
        list1.setAdapter(adapter1);
        list2.setAdapter(adapter2);
        list1.setOnItemClickListener(new SourceSelection());
        list2.setOnItemClickListener(new DestinationSelection());

    }

    public void Draw(){
        map = new Map(this);
        setContentView(map);
    } 

class SourceSelection implements AdapterView.OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            TextView temp = (TextView) arg1;
            Source = temp.getText()+"";
            if(!Source.equals("Blank") && !Destination.equals("Blank")){
                Draw();
            }
        }
    }

    class DestinationSelection implements AdapterView.OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            TextView temp = (TextView) arg1;
            Destination = temp.getText()+"";
            if(!Source.equals("Blank") && !Destination.equals("Blank")){
                Draw();
            }
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    public class Map extends View {
        Paint paint = new Paint();
        public Map(Context context) {
            super(context);
        }
        @Override
        public void onDraw(Canvas canvas) {
            paint.setColor(Color.RED);
            canvas.drawCircle(100, 100, 20, paint);
            canvas.drawLine(2000, 2000, 5000, 5000, paint);
        }
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            // Compute the height required to render the view
            // Assume Width will always be MATCH_PARENT.
            int width = MeasureSpec.getSize(widthMeasureSpec);
            int height = 3000 + 50; // Since 3000 is bottom of last Rect to be drawn added and 50 for padding.
            setMeasuredDimension(width, height);
        }
    }
}
0

There are 0 answers