Does anyone know why my seekbar listener is not picking up any data from the seekbar?? i have it all setup and working but it isnt updating the textviews, i think it has something to do with the popup window using a different activity layout to the activity it sits inside
public class Environment extends Activity implements OnSeekBarChangeListener
{
private ImageButton lockButton;
SeekBar bar;
TextView textProgress, textAction;
private PopupWindow pwindo;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_environment);
lockButton = (ImageButton) findViewById(R.id.lock);
lockButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
initiatePopupWindow();
}
});
}
private void initiatePopupWindow() {
try {
LayoutInflater inflater = (LayoutInflater) Environment.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.annotation,
(ViewGroup) findViewById(R.id.popup_element));
pwindo = new PopupWindow(layout, 1000, 1200, true);
pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);
bar = (SeekBar)findViewById(R.id.seekBar1); // make seekbar object
bar.setOnSeekBarChangeListener(this);
textProgress = (TextView)findViewById(R.id.textViewProgress);
textAction = (TextView)findViewById(R.id.textViewAction);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
textProgress.setText("The value is: "+progress);
textAction.setText("changing");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
textAction.setText("starting to track touch");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
seekBar.setSecondaryProgress(seekBar.getProgress());
textAction.setText("ended tracking touch");
}
} Whenever i use the slider it should update with the int value 0-100 depending on where the slider is, it works if i create an activity and use it straight away, but when i put it in a popupwindow it doesnt do anything??
annotation.xml
<LinearLayout android:id="@+id/popup_element"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#65bea9"
android:orientation="vertical"
android:padding="10sp">
<EditText
android:layout_width="170dp"
android:layout_height="250dp"
android:id="@+id/editText2"
android:layout_gravity="center_horizontal"
android:background="#ffffff"
android:textColor="#000000"
android:hint="@string/hint_annotation"
android:scrollIndicators="right"
android:gravity="top"
android:inputType="textMultiLine"
android:textSize="8pt"/>
<TextView
android:id="@+id/textViewProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="progress displayed here"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center"
android:textSize="6pt"></TextView>
<TextView
android:id="@+id/textViewAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textViewProgress"
android:layout_marginTop="2dp"
android:text="action displayed here"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center"
android:textSize="6pt"></TextView>
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="5dp"
android:max="100"
android:layout_gravity="center"></SeekBar>
<Button
android:id="@+id/btn_close_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/btn_submit"/>
setup environment xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.Environment">
<ImageButton
android:src="@mipmap/unlocked_syn"
android:layout_width="48dp"
android:layout_height="45dp"
android:id="@+id/lock"
android:layout_row="1"
android:layout_column="11" />
</LinearLayout>
Try this, you should be initializing your Seekbar etc by the views from the layout. Simply doing findViewById searches for the views in the activity
private void initiatePopupWindow() {
try {
LayoutInflater inflater = (LayoutInflater) Environment.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.annotation,
(ViewGroup) findViewById(R.id.popup_element));
pwindo = new PopupWindow(layout, 1000, 1200, true);
pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);
bar = (SeekBar)layout.findViewById(R.id.seekBar1); // make seekbar object
bar.setOnSeekBarChangeListener(this);
textProgress = (TextView)layout.findViewById(R.id.textViewProgress);
textAction = (TextView)layout.findViewById(R.id.textViewAction);
} catch (Exception e) {
e.printStackTrace();
}
}