Every time i try to type in the edittext everything goes up and the header disappears. How do i make a linearlayaout linear1 stay put when i try to type in the edittext. i also tried adding "android:windowSoftInputMode="adjustPan">" to the manifest and it is still not working.
This is my layout
<?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="wrap_content"
android:weightSum="100"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear1"
android:weightSum="4"
android:orientation="horizontal"
android:layout_width="0dp"
android:background="#5D4037"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher"
android:isScrollContainer="false"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="51dp"
android:text="TextView"
android:textColor="#f0f0f0"
android:textSize="24sp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView1"
android:layout_toEndOf="#+id/imageView1"
android:layout_marginStart="51dp" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout1"
android:background="#f0f0f0"
android:layout_weight="80"
android:layout_below="#+id/linear1">
</ListView>
<LinearLayout
android:id="#+id/relativeLayout1"
android:weightSum="4"
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#f0f0f0" >
<EditText
android:id="#+id/mess"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:maxHeight="300dp"
android:clickable="true"
android:layout_weight="3"
android:background="#ffffff"
android:focusableInTouchMode="true"
android:scrollbarSize="40dp" >
<requestFocus />
</EditText>
<ImageButton
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_send"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
This is me java class
import com.obi.thinker.logins.R;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class Chatting extends ListActivity {
EditText mess;
ImageButton send;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.yon);
mess = (EditText) findViewById(R.id.mess);
mess.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
}
}
});
}
}
I don't want the soft keyboard to push the header . it should push only the list view up.
Related
I want to build an app that display movies through internet. and i want to use exoplayer to play the movies . I initialized the exoplayer and the exoplayer plays the url i passed to . But i want to change the layout of playback_controller and put my own layout but i dont know how to bind the custom layout with exoplayer.
i also dont how to set the progress bar,default time bar(or seek bar), and other buttons you will see in my layout.
these are my java code
package com.example.novin.exoplayer;
import android.net.Uri;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorInput;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.hls.HlsDataSourceFactory;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
import com.google.android.exoplayer2.ui.DefaultTimeBar;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
import javax.sql.DataSource;
import static com.google.android.exoplayer2.Player.*;
public class MainActivity extends AppCompatActivity {
SimpleExoPlayerView playerView ;
SimpleExoPlayer exoPlayer ;
Uri enternetUri= Uri.parse("https://developers.google.com/training/images/tacoma_narrows.mp4");
ImageButton btnPause , btnPlay;
DefaultTimeBar seekBar ;
RelativeLayout loadingBar ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_exo);
playerView= (SimpleExoPlayerView) findViewById(R.id.playerView);
playerView.setUseController(true);
loadingBar= (RelativeLayout) findViewById(R.id.loading_bar);
btnPause = (ImageButton) findViewById(R.id.btn_pause);
btnPlay = (ImageButton) findViewById(R.id.btn_play);
seekBar= (DefaultTimeBar) findViewById(R.id.exo_progress);
try {
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("exoplayer_video");
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
final MediaSource mediasource = new ExtractorMediaSource(enternetUri, dataSourceFactory, extractorsFactory, null, null);
playerView.setPlayer(exoPlayer);
exoPlayer.prepare(mediasource);
btnPlay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
exoPlayer.setPlayWhenReady(true);
btnPlay.setVisibility(View.GONE);
btnPause.setVisibility(View.VISIBLE);
}
});
btnPause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
exoPlayer.setPlayWhenReady(false);
btnPause.setVisibility(View.GONE);
btnPlay.setVisibility(View.VISIBLE);
}
});
}catch (Exception e){
Log.e("MainActivity","exoplayer error" + e.toString());
}
}
#Override
protected void onPause() {
super.onPause();
exoPlayer.setPlayWhenReady(false);
}
public class ExoplayerClass implements ExoPlayer.EventListener {
#Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
}
#Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
}
#Override
public void onLoadingChanged(boolean isLoading) {
}
#Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
}
#Override
public void onRepeatModeChanged(int repeatMode) {
}
#Override
public void onPlayerError(ExoPlaybackException error) {
}
#Override
public void onPositionDiscontinuity() {
}
#Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
}
}
}
this is my exo_playback_control_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/loading_bar"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/pro_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/root">
<LinearLayout
android:id="#+id/top"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center"
android:paddingRight="50dp"
android:background="#96000000">
<ImageButton
android:id="#+id/btn_back"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#f2ffffff"
android:src="#drawable/ic_back2"
android:layout_gravity="center"
android:layout_marginLeft="5dp"/>
<TextView
android:id="#+id/text_title"
android:text="Video Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="24sp"
android:gravity="center|left"
android:paddingLeft="10dp"
android:textColor="#fefffe"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="40dp" />
<ImageButton
android:id="#+id/btn_cast"
android:src="#drawable/chrom_cast"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="48dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/middle"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/seekbar_time"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#96000000">
<TextView
android:id="#+id/text_current_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="00:00:00"
android:textColor="#ffffff"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingLeft="20dp"/>
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="#+id/exo_progress"
android:layout_marginRight="10dp"
android:layout_width="400dp"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/text_total_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="00:00:00"
android:textColor="#ffffff"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingLeft="0dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:id="#+id/cotrols"
android:layout_width="match_parent"
android:layout_height="48dp"
android:paddingBottom="10dp"
android:background="#96000000">
<ImageButton
android:src="#drawable/lock2"
android:layout_weight="0"
android:id="#+id/btn_lock"
android:scaleType="fitXY"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="right"
android:background="#fafcfa"
android:layout_marginLeft="30dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_marginLeft="70dp"
android:layout_marginRight="70dp">
<ImageButton
android:layout_marginLeft="10dp"
android:src="#drawable/prev"
android:scaleType="fitXY"
android:id="#+id/btn_prev"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:background="#f9fcf9"/>
<ImageButton
android:id="#+id/btn_rev"
android:background="#f2f2f2"
android:scaleType="fitXY"
android:src="#drawable/rewind"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="24dp"/>
<ImageButton
android:background="#f1e2e2"
android:src="#drawable/play"
android:id="#+id/btn_play"
android:layout_marginLeft="24dp"
android:layout_width="32dp"
android:layout_height="32dp" />
<ImageButton
android:background="#0a0a0a"
android:src="#drawable/pouse"
android:layout_marginLeft="24dp"
android:id="#+id/btn_pause"
android:visibility="gone"
android:layout_width="32dp"
android:layout_height="32dp" />
<ImageButton
android:id="#+id/btn_forw"
android:background="#f2f2f2"
android:rotation="180"
android:scaleType="fitXY"
android:src="#drawable/rewind"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="24dp"/>
<ImageButton
android:src="#drawable/prev"
android:scaleType="fitXY"
android:id="#+id/btn_next"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="24dp"
android:rotation="180"
android:layout_gravity="center"
android:background="#f9fcf9"/>
</LinearLayout>
<ImageButton
android:scaleType="fitXY"
android:src="#drawable/subtitles"
android:id="#+id/btn_sub"
android:layout_weight="0"
android:layout_marginRight="24dp"
android:layout_gravity="center"
android:layout_width="40dp"
android:layout_height="40dp"
android:cropToPadding="false"
android:alpha="1"/>
<ImageButton
android:layout_marginRight="20dp"
android:id="#+id/btn_setting"
android:layout_weight="0"
android:layout_gravity="right"
android:scaleType="fitXY"
android:src="#drawable/setting"
android:layout_width="40dp"
android:layout_height="40dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Android Studio is giving me errors in the Main Activity Java over unresolved symbols or id's. As far as I can see the id's refrenced in the java code exist.
In another app which used these same principles, it worked, I cross refrenced the two apps and could not find anything that stood out.
Here is my java code:
package com.example.android.quizapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;
public class QuizMainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz_main);
}
public void display(int value) {
TextView quantityTextView = findViewById(R.id.value_text);
quantityTextView.setText(value);
}
public void slider(View view){
SeekBar seekBar = (SeekBar)findViewById(R.id.i);
int Value = seekBar.getProgress();
EditText text = (EditText)findViewById(R.id.valueText);
String name = text.getText().toString();
text.setText(Value);
}
}
Here is my XML: (The id's are there)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.quizapplication.QuizMainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Quiz"
android:textAlignment="center"/>
<TextView
android:id="#+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="What is you favorite color?"
android:textAlignment="center"
android:paddingTop="20dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="#+id/title"
/>
<TextView
android:id="#+id/value_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textAlignment="center"
android:layout_alignParentBottom="true"
android:layout_marginBottom="300dp"/>
<SeekBar
android:id="#+id/i"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="146dp"
android:onClick="slider"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
Try adding this:
import com.example.android.quizapplication.R;
I'm trying to make an Activity which allows the user to press a button and when he presses it, it generates an EditText and a spinner. The problem is that the scroll view does not scroll. The page stays as is.
XML:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_order_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.nir.nestleapp.OrderItemsActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true">
<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_y="58dp"
android:inputType="phone"
android:ems="10"
android:id="#+id/Quantity"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:hint="quantity"
android:layout_x="11dp" />
<Spinner
android:layout_width="174dp"
android:layout_height="48dp"
android:layout_x="148dp"
android:layout_y="58dp"
android:id="#+id/ItemSpinner" />
</AbsoluteLayout>
</ScrollView>
<Button
android:text="add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="133dp"
android:layout_y="431dp"
android:id="#+id/Generate" />
</AbsoluteLayout>
Java:
package com.example.nir.nestleapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Spinner;
public class OrderItemsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_items);
final AbsoluteLayout layout = (AbsoluteLayout) findViewById(R.id.activity_order_items);
final Spinner Items=(Spinner)findViewById(R.id.ItemSpinner);
final Button Generate=(Button)findViewById(R.id.Generate);
final EditText Quantity=(EditText)findViewById(R.id.Quantity);
final float[] yPlacement = {280};
Generate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Spinner GeneratedSpinner=new Spinner(OrderItemsActivity.this);
EditText GeneratedQuantity=new EditText(OrderItemsActivity.this);
layout.addView(GeneratedSpinner);
GeneratedSpinner.setX(Items.getX());
yPlacement[0] =yPlacement[0]+200;
GeneratedSpinner.setY(yPlacement[0]);
layout.addView(GeneratedQuantity);
GeneratedQuantity.setX(Quantity.getX());
GeneratedQuantity.setY(yPlacement[0]);
GeneratedQuantity.setHint("quantity");
GeneratedQuantity.setWidth(300);
}
});
}
You can change your Absolute layout, use as child LinearLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_y="58dp"
android:inputType="phone"
android:ems="10"
android:id="#+id/Quantity"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:hint="quantity"
android:layout_x="11dp" />
<Spinner
android:layout_width="174dp"
android:layout_height="48dp"
android:layout_x="148dp"
android:layout_y="58dp"
android:id="#+id/ItemSpinner" />
</LinearLayout>
</ScrollView>
Changing AbsoluteLayout into a LinearLayout is the best way to get rid from this issue.
main activity.java
package abhilmohan.blogspot.com;
import android.R.string;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.ActionBar;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
EditText amount1;
EditText amount2;
EditText amount3;
EditText amount4;
Button calculate;
double w=0;
double x=0;
double y=0;
double z=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar bar= getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
}
public void initcontrols() {
amount1=(EditText)findViewById(R.id.editText1);
amount2=(EditText)findViewById(R.id.editText2);
amount3=(EditText)findViewById(R.id.editText3);
amount4=(EditText)findViewById(R.id.editText4);
calculate=(Button)findViewById(R.id.button1);
}
public void calculate() {
w=Double.parseDouble(amount1.getText().toString());
x=Double.parseDouble(amount2.getText().toString());
y=w/12;
amount3.setText(Double.toString(y));
z=w*x/100;
amount4.setText(Double.toString(z));
}
public void gotoactivity (View v) {
Intent intent = new Intent(this,ResultPage.class);
calculate();
startActivity(intent);
}
am not getting result while calling calculator() void method on button click.i want my results to be published in two textviews created in reulst_page layout
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:gravity="left"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="abhilmohan.blogspot.com.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:layout_marginRight="40dp"
android:text="#string/ctc"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_marginTop="-15dp"
android:inputType="number"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:padding="20dp"
android:paddingBottom="50dp"
android:textColor="#000000" />
<TextView
android:id="#+id/textView2"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="90dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="-30dp"
android:text="#string/TDS"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="-70dp"
android:background="#drawable/rounded_edit_text"
android:inputType="number"
android:ems="10"
android:padding="20dp"
android:paddingBottom="50dp" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="177dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:background="#drawable/button_style"
android:text="#string/ok"
android:textColor="#ffffff"
android:onClick="gotoactivity" />
</LinearLayout>
</RelativeLayout>
resultpage.java
package abhilmohan.blogspot.com;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.app.ActionBar;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
public class ResultPage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result_page);
getActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar bar= getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()== android.R.id.home)
{
finish();
}
return super.onOptionsItemSelected(item);
}
}
result_page.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:layout_marginRight="40dp"
android:text="#string/amount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_marginTop="-15dp"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:inputType="number"
android:padding="20dp"
android:paddingBottom="50dp"
android:textColor="#000000"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView
android:id="#+id/textView2"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="90dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="-30dp"
android:text="#string/tdsamount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="-70dp"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:inputType="number"
android:padding="20dp"
android:paddingBottom="50dp"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button2"
android:layout_width="177dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:background="#drawable/button_style"
android:text="#string/rate"
android:textColor="#ffffff" />
</LinearLayout>
At the moment you are executing calculate() in the MainActivity.java second activity called ResultPage doesn't exist, therefore you can't change it's view (editText3and editText4).
In order to pass data to another activity you should fill your Intent with some extra data and then in your ResultPage activity's onCreate you would get underlying extras.
EDIT
MainActivity.java
public void gotoactivity (View v) {
calculate();
Intent intent = new Intent(this, ResultPage.class);
intent.putExtra("AMOUNT_3", y);
intent.putExtra("AMOUNT_4", z);
startActivity(intent);
}
ResultPage.java inside onCreate
Bundle extras = getIntent().getExtras();
if (extras != null) {
int amount3 = extras.getInt("AMOUNT_3");
int amount4 = extras.getInt("AMOUNT_4");
}
I am trying to create a View with an image and a list view in linear layout with vertical orientation and a EditText that should be on top all the times. I should be able to scroll the image and listview together, but not the EditText at the bottom.
I am somewhat new to android and sorry if i am not making any sense. ask me anything you need for additional info.
Here is my code..
<?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">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#CDBCDE">
<FrameLayout
android:id="#+id/post_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/post_profilePictureView1"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:maxHeight="75dp"
android:maxWidth="75dp"
android:padding="5dp"
android:src="#drawable/ic_launcher_web"/>
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="85dp"
android:layout_marginTop="15dp"
android:weightSum="1">
<TextView
android:id="#+id/post_nameView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:maxLength="20"
android:maxLines="1"
android:singleLine="true"
android:text="Name"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
<ListView
android:id="#+id/commentsListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/post_container"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginBottom="8dp"
android:background="#CCBBAA"/>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#EDf3F4"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:focusable="true"
android:focusableInTouchMode="true">
<EditText
android:id="#+id/newCommentTextView"
android:layout_width="315dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:nextFocusUp="#id/newCommentTextView"
android:hint="Write your comment..."
android:textSize="20dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:fontFamily="sans-serif-light"
android:background="#FFFFFF">
</EditText>
<ImageView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_toRightOf="#id/newCommentTextView"
android:id="#+id/newCommentPostButton"
android:text="comment"
android:padding="3dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</RelativeLayout>
and the java code is
package com.example.soquestion;
import java.util.ArrayList;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().hide();
ListView listview = (ListView) findViewById(R.id.commentsListView);
String[] values = {"January","February","March","April","May","June","July","August","September","October",
"November","December"};
ArrayList<String> arrayList = new ArrayList<String>();
for (int i = 0; i < values.length; ++i) {
arrayList.add(values[i]);
}
final ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, arrayList);
listview.setAdapter(adapter);
}
}