Kotlin Headerstate messing up display on Android TV - android

so I'm new to Kotlin. Been working in it for a few weeks. I am currently trying to figure out how to remove the blue banner header thingy. When I try to remove the banner using headersState = BrowseSupportFragment.HEADERS_DISABLED it makes the whole page go blank.
This is what it looks like with the HEADERS_ENABLED
private fun setupUIElements() {
//title = getString(R.string.browse_title)
// over title
headersState = BrowseSupportFragment.HEADERS_ENABLED
isHeadersTransitionOnBackEnabled = true
// set fastLane (or headers) background color
brandColor = ContextCompat.getColor(activity!!, R.color.fastlane_background)
// set search icon color
searchAffordanceColor = ContextCompat.getColor(activity!!, R.color.search_opaque)
}
Screen Shot with Header Enabled
This is what it looks like when I set headersState = BrowseSupportFragment.HEADERS_DISABLED
Screen shot with Header Disabled
Basically I'm trying to get it to show all the video's with out the blue thing on the left.
I think this function might have something to do with the issue, but I'm not 100% sure.
private fun loadRows() {
val list = MovieList.list
val rowsAdapter = ArrayObjectAdapter(ListRowPresenter())
val cardPresenter = CardPresenter()
for (i in 0 until NUM_ROWS) {
if (i != 0) {
Collections.shuffle(list)
}
val listRowAdapter = ArrayObjectAdapter(cardPresenter)
for (j in 0 until NUM_COLS) {
listRowAdapter.add(list[j % 5])
}
val header = HeaderItem(i.toLong(), MovieList.MOVIE_CATEGORY[i])
val row_list = ListRow(header, listRowAdapter)
rowsAdapter.add(row_list)
}
adapter = rowsAdapter
}

Related

Delete a image in a ImaveView programmatically created using kotlin

I need to display a different image according to a condition. The problem is that the previous image remains visible under the next image?
I have nowhere found using the correct command to delete the previous image before displaying the next one.
private fun showDecision(warning: String) {
var imgResId = 0
var resId = 0
// accessing our custom image which we have in drawable folder
when (warning) {
"wrong" -> {
imgResId = R.drawable.wrong
resId = imgResId
}
"notGood" -> {
imgResId = R.drawable.notGood
resId = imgResId
}
"bad" -> {
imgResId = R.drawable.bad
resId = imgResId
}
}
// image de l'arbitre
val decisionView = ImageView(this)
// setting height and width of imageview
decisionView.layoutParams = RelativeLayout.LayoutParams(392, 700)
decisionView.x = hut.x - 80 // setting margin from left
decisionView.y = aDecision.y // setting margin from top
// accessing our relative layout from activity_main.xml
decisionLayout = findViewById<RelativeLayout>(R.id.decision_layout)
decisionView.setImageResource(resId)
// Add ImageView to linearLayout
decisionLayout?.addView(decisionView) // adding image to the layout
decisionLayout?.visibility = View.VISIBLE
decisionShown = true
}
setBackgroundResource(0) does nothing.
Before that, in my onClick(view: View?) I use GONE as below
if (decisionShown) {
decision_layout.visibility = View.GONE
decisionShown = false
}
What did I not do correctly? Thank you
You can clear imageview content by calling setImageDrawable(null);
imgView.setImageDrawable(null);
such usage is documented in the official docs: ImageView#setImageDrawable .
The right instruction is view.removeAllViews() for me and it works. Why "AllViews"? Just because it could be some views, not only the one preceded.

When I click the button of Activity 2, I want to add a container to Activity 1

I'm copying code from an Android alarm app.
After setting up the alarm, I want to know how to add a container to the main screen when I press the Save button.
To sum up, my question is:
When you click a button on Activity2,
This is how to add a new container to the Activity1.
savebtn.setOnClickListener {
var item_view = R.layout.alram_list
var alram_title = alram_title1
var alram_time = alram_time
var al_on = al_on
var intent1 = Intent(this#AdeDetail, MainActivity::class.java)
intent1.putExtra("title", title)
intent1.putExtra("day", t)
intent1.putExtra("hour", hour)
intent1.putExtra("min", min)
startActivity(intent1)
}
This is part of activity code 1.
If the statement keeps false and does not seem to receive the value. I'll be waiting for your help. Thank you.
if (intent1.getStringExtra("title") != null){
Log.d("title","111")
var title = intent.getStringExtra("title")
var min = intent.getStringExtra("min")
var hour = intent.getStringExtra("hour")
var day = intent.getStringExtra("day")
var inflater = LayoutInflater.from(this#MainActivity)
var item_view = inflater.inflate(R.layout.alram_list, null)
var alram_time = item_view.findViewById<TextView>(R.id.alram_time)
var alram_title = item_view.findViewById<TextView>(R.id.alram_title1)
var alram_on = item_view.findViewById<RadioButton>(R.id.al_on)
alram_time.text = day+ "hour:" +"min"
alram_title.text = title
alram_on.isChecked =true
container.addView(item_view)
}
First of you need to write receiving intent in 2nd activity like
var intent = getIntent();
then you can retrive values like
intent.getStringExtra("title")
same for others

Text is updated only once on button click

In my project, there are some products..
I created a text beside the button, and when this button is clicked the amount of text should be increased.
My code increases the amount of text only once.
My code:
holder.add.setOnClickListener {
val num = 1
val add = num+1
holder.amount.text = add.toString()
}
}
change the code in this way.
var num = 1
holder.add.setOnClickListener {
val add = num+1
holder.amount.text = add.toString()
}
The reason behind that, at every button click num is initialized with 1.
Lets create a global variable num and everytime button is clicked then num will get updated
var num = 1
holder.rl_additvie.visibility = View.GONE
holder.addicon.setOnClickListener {
holder.rl_additvie.visibility = View.VISIBLE
holder.remmove.visibility = View.GONE
num = num+1
holder.amount.text = num.toString()
}

Cannot reposition axes in bar graph OxyPlot xamarin

I have displayed a bar graph in android xamarin. I want to display a simple bar graph with 3 categories.
What I want:-
What I get :-
So currently my graph is showing horizontally. I want it to show as in figure 1.
Here is my code:-
var plotModel1 = new PlotModel();
plotModel1.LegendOrientation = LegendOrientation.Vertical;
plotModel1.PlotAreaBorderColor = OxyColors.White;
var barSeries1 = new BarSeries();
for (int i = 0; i < barValues.Length && i < colorPallete.Length && i<barTitles.Length; i++)
{
barSeries1.Items.Add(new BarItem(barValues[i], -1) { Color = OxyColor.Parse(colorPallete[i]) });
}
plotModel1.Series.Add(barSeries1);
MyModel = plotModel1;
barPlotView.Model = MyModel;
Instead of BarSeries you should look up ColumnSeries. It will give you the horizontal graph you are looking for.

Set imageview background on button click?

lets say I have a timer activity. Theres an image view that displays a number of 0 - 9(these are viewed as images, NOT text).
eg. the images names are clock_0, clock_1, clock_2...clock_9.
There is a plus and minus button that should change a counter(to pick the image). If current image is clock_0, pressing the plus button will change the view to clock_1 etc. How do I do this efficiently?
EDIT
Heres what I tried to do;
set an int[],
int[] clockResource = new int[10];
clockResource[0] = R.drawable.clock_0;
clockResource[1] = R.drawable.clock_1;
clockResource[2] = R.drawable.clock_2;
clockResource[3] = R.drawable.clock_3;
clockResource[4] = R.drawable.clock_4;
clockResource[5] = R.drawable.clock_5;
clockResource[6] = R.drawable.clock_6;
clockResource[7] = R.drawable.clock_7;
clockResource[8] = R.drawable.clock_8;
clockResource[9] = R.drawable.clock_9;
assign an onclicklistener for the addbutton
case R.id.addMin:
if (addMin.isEnabled()) {
if (mintwo < 9) {
mintwo++;
} else if (mintwo == 9) {
minone++;
mintwo = 0;
}
min2.setBackgroundResource(clockResource[mintwo]);
min1.setBackgroundResource(clockResource[minone]);
}
Since they're ImageViews, use setImageDrawable or setImageResource instead.
Related SO-question.
case R.id.addMin:
if (addMin.isEnabled()) {
if (mintwo < 9) {
mintwo++;
} else if (mintwo == 9) {
minone++;
mintwo = 0;
}
min2.setImageResource(clockResource[mintwo]); //updated
min1.setImageResource(clockResource[minone]); //updated
}

Categories

Resources