Hi i'm new to android programming and i'm having this issue where i'm sure that my code should work but doesn't.
This is my MainActivity.java:
package com.example.evo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
public class MainActivity extends Activity {
ImageButton imageButton2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.open);
imageButton2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SecondScreenActivity.class);
}
} );
}
}
This is my SeconScreenActirity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
public class SecondScreenActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.high_score);
}
}
This is my highscore.xml layout file
<?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/yedi"
android:orientation="vertical" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="220dp"
android:text="high scores"
android:textColor="#FA5882" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="29dp"
android:text="Evrim"
android:textColor="#00FFFF" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="320dp"
android:layout_marginTop="-17dp"
android:text="1528"
android:textColor="#CC2EFA" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="20dp"
android:text="Selin"
android:textColor="#00FFFF" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="320dp"
android:layout_marginTop="-17dp"
android:text="1016"
android:textColor="#CC2EFA" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="11dp"
android:text="Muhammed"
android:textColor="#00FFFF" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="320dp"
android:layout_marginTop="-17dp"
android:text="800"
android:textColor="#CC2EFA" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="72dp"
android:layout_height="0dp"
android:layout_marginTop="80dp"
android:layout_weight="0.16"
android:src="#drawable/abc_ic_ab_back_holo_light"
android:contentDescription="#string/todo"/>
</LinearLayout>
This is my open.xml where i have my imageButton2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/son"
android:paddingBottom="#dimen/activity_horizontal_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_horizontal_margin"
android:screenOrientation="landscape"
tools:context="com.example.kkk.MainActivity$PlaceholderFragment" >
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/highscore" android:contentDescription="#string/todo"/>
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_above="#+id/imageButton2"
android:layout_alignLeft="#+id/imageButton2"
android:src="#drawable/play" android:contentDescription="#string/todo"/>
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="#+id/imageButton3"
android:layout_centerHorizontal="true"
android:src="#drawable/exit" android:contentDescription="#string/todo"/>
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/imageButton2"
android:layout_below="#+id/imageButton2"
android:src="#drawable/aboutt" android:contentDescription="#string/todo"/>
</RelativeLayout>
I also updated my AndroidManifest.xml to add SeconScreenActivity.java
And i'm getting this
java.lang.RuntimeException: Unable to start activity
ComponentInfo java.lang.NullPointerException
errors please plase help!
You never initialize your imageButton element in your first activity.
So you get the NullPointerException when trying to assign to it the click listener.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.open);
//or whatever the id is for the image button in the open layout
imageButton2 = (ImageButton) findViewById(R.id.imageButton2);
imageButton2.setOnClickListener(new View.OnClickListener() {
You missed to take reference of ImageButton from open layout:
imageButton2 = (ImageButton) findViewById(R.id.<ImageButtonIdInOpenXml);
Just add below line
imageButton2 = (ImageButton)findViewById(R.id.imageButton1);
after
setContentView(R.layout.open);
Your are getting error because view ImageButton is not initialized
Related
I have lots of layouts and activites and fragments. There are tabs in one activity called Hastane1 and it has four tabs in it. They don't have any problem but one of them has. I wanted to send a data from one Activity to a Fragment. They are seperate. Fragment is in Hastane1 activity but Haberlesme1 activity is in another place. It supposed to send the numbers which i entered in the activity called Haberlesme1 to the textView in the fragment called Hastane1Tab3Frag which is a tab of Hastane1.
The Android Studio itself doesn't have any errors but when i run the app on my phone, it stops when i pressed the button called "Gönder" (#id/button8).
Haberlesme1 (Activity):
package com.example.projev021.İllerPackage.KocaeliPackage.GebzePackage.GebzeFragments.Hastane1Fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.example.projev021.HaberlesmePackage.Haberlesme1;
import com.example.projev021.R;
public class Hastane1Tab3Frag extends Fragment {
Button goster;
TextView sonucText;
int sayi=0;
Haberlesme1.Ogrenci ogr;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.hastane1_tab3,container,false);
goster=(Button)v.findViewById(R.id.button13);
sonucText = (TextView)v.findViewById(R.id.textView3);
goster.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sonucText.setText(sayi);
}
});
return v;
}
public void sendData(int birinciSayi) {
this.sayi=birinciSayi;
}
public void sendOgrenci(Haberlesme1.Ogrenci ogrenci) {
this.ogr=ogrenci;
}
}
haberlesme1.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:fontFamily="#font/lineto_circular_black"
android:text="#string/kackisivar"
android:textSize="50sp"/>
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:ems="10"
android:inputType="number"
android:text="" />
<Button
android:id="#+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"
android:background="#drawable/buttonshape"
android:fontFamily="#font/lineto_circular_black"
android:text="#string/gonder"
android:textColor="#FFC107"
android:textSize="30sp"
android:onClick="calistir"/>
</LinearLayout>
Hastane1Tab3Frag (Fragment):
package com.example.projev021.İllerPackage.KocaeliPackage.GebzePackage.GebzeFragments.Hastane1Fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.example.projev021.HaberlesmePackage.Haberlesme1;
import com.example.projev021.R;
public class Hastane1Tab3Frag extends Fragment {
Button goster;
TextView sonucText;
int sayi=0;
Haberlesme1.Ogrenci ogr;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.hastane1_tab3,container,false);
goster=(Button)v.findViewById(R.id.button13);
sonucText = (TextView)v.findViewById(R.id.textView3);
goster.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sonucText.setText(sayi);
}
});
return v;
}
public void sendData(int birinciSayi) {
this.sayi=birinciSayi;
}
public void sendOgrenci(Haberlesme1.Ogrenci ogrenci) {
this.ogr=ogrenci;
}
}
hastane1tab3.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/container">
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="10dp"
android:fontFamily="#font/lineto_circular_black"
android:text="#string/kisisayisi_"
android:textSize="50sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:fontFamily="#font/lineto_circular_black"
android:text=""
android:textSize="100sp"
android:textColor="#000000" />
<Button
android:id="#+id/button13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"
android:background="#drawable/buttonshape"
android:fontFamily="#font/lineto_circular_black"
android:text="#string/goster"
android:textColor="#FFC107"
android:textSize="30sp"/>
</LinearLayout>
</FrameLayout>
And the screenshots:
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>
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.
How can I change or add more code to make this app to stop crashing? This activity is called "WhatBin", I simply wanted to make a button listen to when a person would click and change a text view. (VIEW PICTURES BELOW FOR MORE DETAILS.)
PICTURES: http://imgur.com/a/ODvHb
package com.example.tiffany.whatbin;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;
public class WhatBin extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_what_bin);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final TextView txt_answer = (TextView) findViewById(R.id.txt_answer);
Button btn_go = (Button) findViewById(R.id.btn_go);
btn_go.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txt_answer.setText("Marker - Recycle Bin");
}
});
};
}
HERE IS THE XML FILE:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_padddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_what_bin" tools:context=".WhatBin">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go"
android:id="#+id/btn.go"
android:layout_marginBottom="113dp"
android:textColor="#drawable/abc_dialog_material_background_dark"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textEdit"
android:layout_alignBottom="#+id/btn.go"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/btn.go"
android:layout_toStartOf="#+id/btn.go" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/instructiontext"
android:id="#+id/textinstruc"
android:layout_below="#+id/textEdit"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/btn.go"
android:layout_toStartOf="#+id/btn.go" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/txt.1"
android:id="#+id/txt.answer"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
UPDATE
You are currently using abc_dialog_material_background_dark as textcolor. As you can see in the source of this resource, it is basically a shape. And, shape cannot be used for textcolor.
In your XML file at line 17 you have used a color. That color is of wrong type. My guess, you have used a drawable instead of a color.
Post your activity_what_bin.xml for further explanation.
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);
}
}